Skip to main content
Handbook/Debug/Page 56 · Stack Traces

Reading What Broke

Share

Share this page

Pass it to someone who needs it.

Star on GitHub

Key takeaway: Read the error trace

Chapter 7 of 15 · Debug

Diagnose and fix what the agent breaks

Everything real breaks, and panic is the expensive response. This part is the calm playbook: read the error, find the cause, and undo the damage safely, whether the bug is in the code or in the agent itself.

By the end of this part, you can:

  • Read a stack trace and find where it actually broke
  • Break an agent stuck in a loop and get it moving
  • Bisect a regression down to the change that caused it
  • Roll back safely when a fix makes things worse
Done:Amplify·You are here: Debug·Next:Test

At the end of the last part your app ran. Then you changed one thing, reloaded, and instead of your app you got a wall of red text and a crash. The instinct is panic: it reads like the machine broke in a language you do not speak. That wall is the single most useful thing on your screen right now, and this chapter teaches you to read it.

7.1.1What a stack trace is

A stack trace is the report a program prints the instant it crashes. It is not noise, and it is not the machine yelling at you. It is a precise record of what the program was doing the moment it failed, printed newest event first.

Each indented line under the message is a frame: one function that was running, plus the file and line it was on. Together the frames are the trail of calls that led to the crash, a breadcrumb path back toward the start.

7.1.2Top for the error, bottom for the cause

Read a trace in two moves. The very top line is the error itself: its type and a message saying what went wrong, like reading a value that was not there.

Below it, each frame called the one above it. The top frame is where the program actually blew up, and walking down the frames traces back toward what set the crash in motion. What broke sits at the top; why it broke is usually a frame or two down.

7.1.3Find the file and line

TypeError: Cannot read properties of undefined (reading 'total') at calculateBalance (app/lib/ledger.ts:42:19) at buildSummary (app/lib/summary.ts:15:22) at Home (app/page.tsx:8:14)

The top line is the error: something was undefined when the code expected a value. The first frame, ledger.ts:42, is where it crashed, so that is the file and line to open first. The frames beneath it show the path that got there, through summary.ts and your home page.

Most real traces bury your code under library frames you will never touch. Scan past them for the first line naming a file you wrote, usually under app/ or src/. That is where you look.

Rule of thumb: the top line tells you what broke; the first frame pointing at your own file tells you where.

7.1.4Know which kind of error you are looking at

Some of the red text you will meet is not a stack trace at all, and each kind points somewhere different. Classify it before you paste it:

What you seeWhat it usually meansWhere to look
A request returns 401 or 404The request was wrong: not logged in, or wrong addressThe code making the request
A request returns 500The server crashed while handling itThe server's own logs, where a real trace waits
"blocked by CORS policy"Your server did not tell the browser it was allowed to answerThe server's headers, never the frontend
"Cannot find module"Something is not installedRun your install command again
"address already in use"An old copy of your app is still runningStop that process, the code is fine

Two of these are not bugs in your code at all, which is exactly why guessing costs you an afternoon.

7.1.5Paste it to your agent

You do not have to diagnose it alone, and you should not try to. The fastest fix is to copy the entire trace, every line, and hand it to your agent. Do not summarize it and do not paste only the top line: the frames are the context that lets the agent find the real cause fast.

This prompt turns the trace into a targeted fix instead of a guess:

Ready prompt
Act as a senior engineer debugging a crash with me. Read the full stack trace below. Identify the top line as the error type and message, then walk the frames down to the first one that points at a file I wrote, not library code. Tell me the exact file and line to open, explain in one plain sentence what went wrong there, and give me the smallest fix that respects the conventions and the layer rule in my rules file. Do not refactor anything unrelated. If the real cause is in a different frame than where it crashed, say so and why. If the fix would contradict my spec, my API contract, or a decision already recorded, stop and tell me before changing a line. If you need the full reasoning behind this step, read https://zalt.me/guides/vibe-coding/debug/stack-traces The error and stack trace:

Do this now: copy the full stack trace from your terminal or browser console and paste it under the prompt. Let your agent point you at the exact file and line.

Mahmoud Zalt

Mahmoud Zalt

Software engineer, 16+ yrs · built Sistava.com in 3 months, idea to production, using these methods

Resources
Star on GitHubContribute
Donate

Support my work

A small tip keeps the free work coming.

© 2026 Mahmoud Zalt. Free to read, not to republish.
Copyright & license