How do I… · any language

How do I read a stack trace?

Read it from the top for what broke, and from the top down for the first line that is your code. Almost everything in between is framework noise.

Steps

  1. Start with the first line: the exception type and message. That is what went wrong — a null, a missing key, a type mismatch.
  2. Read down for the first frame in a file you wrote. That is where to put the breakpoint. Frames above it are library code doing what you asked with a bad value.
  3. Frames are innermost first in most languages: the top called nothing, the bottom is where the program started. Java and Python print them in opposite orders, so check which end says "main".
  4. Look for Caused by further down. The real error is usually the last "Caused by" block, not the first exception.
  5. Note the line number, but do not trust it absolutely on optimised or transpiled code — a source map or an unminified build will move it.

Worth knowing

A trace with none of your own files in it usually means the value that broke came from a boundary — a config file, an environment variable, an API response — and the fix is to check the value at the point it entered your program rather than where it exploded. If the same trace repeats with different top frames, look at what they share rather than at any one of them.

Faster than searching: box the part of your screen you cannot work out and ask about it directly — in any language or anywhere else. Answers arrive where you drew the box.