A stack trace lists the chain of function calls that led to an error. Learn where to look first, how to ignore the noise, and how to find your own code quickly.
Your program crashes and a long block of text fills the screen. Beginners often glance at it, feel overwhelmed and start guessing. Experienced developers read it calmly, because they know it follows a simple pattern and tells them almost exactly where to look.
What a stack trace is
When one function calls another, which calls another, the program keeps a list of these calls, called the call stack. If an error happens, the language prints that list. It answers the question: “how did we get here?”
A real example
Traceback (most recent call last):
File "app.py", line 14, in <module>
main()
File "app.py", line 10, in main
user = load_user("42")
File "app.py", line 6, in load_user
return parse_date(row["joined"])
File "dates.py", line 3, in parse_date
return datetime.strptime(text, "%Y-%m-%d")
ValueError: time data '12/05/2026' does not match format '%Y-%m-%d'Where to look, in order
- Read the error message first. Here it is
ValueError: time data '12/05/2026' does not match format. It already tells you the date was in the wrong format. - Find the line that is in your own code. Skip lines from libraries and frameworks at first.
- Look at the exact file and line number, then read a few lines around it.
- Walk up the chain to see which function passed in the bad value.
Ignore the noise, but know why it is there
Real traces often include many lines from frameworks. They are not wrong, just long. Scan for file paths that belong to your project, and treat the rest as context.
TypeError: Cannot read properties of undefined (reading 'name')
at showUser (/app/src/profile.js:12:20)
at handleRequest (/app/src/server.js:40:5)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at next (/app/node_modules/express/lib/router/route.js:144:13)The first line says what went wrong. The first path inside your own code, /app/src/profile.js:12:20, says where. The node_modules lines are the framework passing the request along.
Common messages, in plain words
| Message | Usually means |
|---|---|
undefined is not a function, X is not callable | You called something that is not a function, often a typo or a missing import |
Cannot read properties of undefined | You asked for a property on something that has no value yet |
KeyError, IndexError | A key or position does not exist in the dictionary or list |
NullPointerException | A variable that should hold an object holds nothing |
ModuleNotFoundError, Cannot find module | A package is not installed, or the path is wrong |
When you are stuck
- Copy the error message (not the whole trace) into a search engine.
- Add a print or log line just before the failing line to see the actual values.
- Use a debugger to pause at the line and inspect variables.
- When asking for help, include the full trace, your code around that line, and what you expected to happen.