How do I read a stack trace?
Start at the top
A stack trace starts with the error type and message, such as TypeError or KeyError, followed by a list of frames. Each frame shows a file, a line number, and often a function name. The first line of the message tells you what went wrong, and the frames tell you where and how it was reached.
Many frames will come from libraries or the language runtime. Scan the list for the first frame that points to a file you wrote. That is usually the place to start looking, even if the real cause is a value passed in from elsewhere.
- Read the error message line first
- Find the first frame from your own files
- Check the line number in your editor
- Follow the chain of calls back toward the entry point
Use it with your code
Open the file at the line number shown and look at the variables involved. Add a log just before that line to see the actual values. Often the bug is a value that is not what you assumed, and the stack trace only shows where it crashed.
Reproduce the error with the smallest input you can, then trace the data back through the frames. A short reproduction makes the cause easier to see and easier to confirm once fixed.
Common mistakes
- Only reading the bottom line and ignoring the error message at the top.
- Assuming the line that crashed is always where the bug lives.

Related questions
- What does NullPointerException mean in Java?
- How do I fix IndexError: list index out of range in Python?
- What does TypeError: 'NoneType' object is not subscriptable mean?
- Why do I get a segmentation fault in C?
- What does ValueError: could not convert string to float mean?
- How do I fix a stack overflow error?