Reading Stack Traces
Python tracebacks, Java "Caused by" chains, Node.js stacks — find the root cause fast
Stack trace reading strategy
- Python: read from the bottom up — root cause is the last line
- Java: find the last "Caused by:" — that is the underlying root cause
- Node.js: skip node_modules lines, focus on your own code
- Anatomy: File path → line number → function name → code snippet → exception
- RecursionError / stack overflow → missing base case or circular reference
Question 0 of 5
A Python traceback says "Traceback (most recent call last)" at the top. Where is the root cause of the error?
- Start from the bottom — the last line is the exception type and message (the actual error)
- The lines above show the call chain that led there
- "Most recent call last" means the most recent call is listed just above the error line
KeyError: 'user_id' — this is what you fix. The lines above tell you which function called which, but the error itself is at the bottom.In this Python traceback excerpt, what is the file and line number where the error occurred?File "app/services/user.py", line 47, in get_user
return db.query(User).filter(User.id == user_id).one()
sqlalchemy.orm.exc.NoResultFound: No row was found...
File "path/to/file.py"— the source file pathline 47— the exact line numberin get_user— the function name- The next line shows the actual code that raised the error
- The last line names the exception class and message
A Java stack trace contains: Caused by: java.sql.SQLTimeoutException: Statement cancelled due to timeout. What does "Caused by" mean?
- When code catches an exception and wraps it in a new one:
throw new ServiceException("Failed", e), the stack trace shows the outer exception first, then "Caused by:" with the original - Reading strategy: find the last "Caused by:" — that is the root cause
- There can be multiple levels of "Caused by:" in complex frameworks (Spring, Hibernate)
You see this at the end of a Python traceback: RecursionError: maximum recursion depth exceeded. What does this tell you about the code?
- Missing base case in a recursive function
- Circular references in serialization (object A contains B, B contains A)
- Accidental mutual recursion (A calls B, B calls A)
RangeError: Maximum call stack size exceeded.In a Node.js stack trace, you see lines from node_modules/express/lib/router/index.js mixed with your own code. Which lines should you focus on first?
- Skip framework/library lines (express, lodash, mocha, etc.) until you find your own code
- The topmost line in your own code is usually where the error propagated from
- If all lines are framework code, the error may be in incorrect usage (wrong parameters, missing config)