How to Read a Stack Trace Without Panicking
A stack trace is a map, not an error message. Here is how to find the one line that matters.
A stack trace is not the error. It is the list of calls that led to the error, with the newest call at the top and the oldest at the bottom. Most people read the top line, see something unfamiliar, and give up. The useful line is usually a few below that.
What the lines actually say
Traceback (most recent call last):
File "app.py", line 42, in <module>
total = checkout(cart)
File "app.py", line 28, in checkout
return apply_discount(total, user)
File "app.py", line 19, in apply_discount
return total * (1 - user.discount_rate)
AttributeError: 'NoneType' object has no attribute 'discount_rate'
Read the last line first. That is the error: something was None and we asked it for an attribute. Then walk up until you find the frame that belongs to your code and where the bad value entered. Here user is None at line 19, and line 28 is the call that passed it in.
The frame you want
Your own file, not the library. If the trace is all site-packages, the bug is usually in the arguments you passed in. The first frame that is your code is where to start reading.
In JavaScript the order is reversed: the error comes first, then the call stack, innermost at the top.
TypeError: Cannot read properties of undefined (reading 'name')
at renderUser (user.js:12:20)
at UserList (list.js:8:9)
renderUser received something undefined. Look at what UserList passed it.
When your code is not in the trace
That means the failure happened inside a framework before your code ran, or after it returned. Check the request, the config, or the data you handed over. A trace with no frames of yours is still telling you something: the problem is at the boundary.
Recursion
Deep traces that repeat the same function are a missing base case. Count the repeats, then read the arguments at each level. The one where the argument stops changing is where the condition failed.