Jake Anto

Read the whole stack trace

1 min read

A habit worth building: when something throws, read the entire trace before touching any code. The top frame tells you where the program gave up, not where it went wrong.

Consider a null dereference deep inside a serialization library:

function toPayload(user: User) {
    return {
        id: user.id,
        joined: user.joinedAt.toISOString(),
    };
}

The exception points at toISOString. The actual bug is several frames up, wherever a User was constructed without joinedAt — probably a fixture, a cache deserialization, or a migration that left the column null.

A rough order of operations

  1. Read every frame you own, bottom to top. Skip framework frames on the first pass.
  2. Find the lowest frame in your own code. That’s usually where the bad value entered.
  3. Only then look at the throwing line.

The trace is a narrative, and the last sentence rarely explains the plot.

Tags

  • debugging
  • practices
All posts