How do I read a stack trace?

Updated October 2026 · How we answer

Short answerRead the error message first, then find the first line that points to your own code. Stack traces list calls from most recent to oldest, so the top frames show where the error happened.

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.
From our shopsCaseMorph: Type an idea, see a custom phone case in seconds, then print a one-of-one.