Feeding the AI the right context
This is where most of your leverage is. When you report a bug, include:
- The error message, verbatim. Copy it exactly — don't paraphrase. Paraphrasing an error is like describing a photo over the phone: you'll leave out the one detail that mattered.
- The stack trace, especially the top few lines.
- The relevant code — the function that threw, plus anything it calls.
- What you expected versus what happened.
Here is what a strong debugging actually looks like:
I'm getting an error when I submit the signup form. Here's the full output:
TypeError: Cannot read properties of undefined (reading 'email')
at validateUser (src/auth/validate.js:14:23)
at handleSignup (src/routes/signup.js:31:10)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Steps to reproduce: fill in the form, click "Sign up".
Expected: a "Welcome" message.
Actual: the page goes blank and the error above appears in the console.
Here is validate.js (lines around 14):
[paste the function]
And here is the handleSignup function that calls it:
[paste the function]
What could be causing this, and how do I confirm it before changing anything?
Notice that last line. You are asking for a hypothesis and a confirmation step, not an immediate edit. That keeps the AI honest.
It helps to know how to read the trace you're pasting. A stack trace is a call history, newest first: the top line is where the program actually exploded, and each line below is the function that called the one above it. So in the example, validateUser is where email was read off something undefined, and handleSignup is who called validateUser. The frames below your own code — like processTicksAndRejections — belong to the language runtime; you can usually ignore them. Read top-down until you hit the first line that points at your file, and that's almost always where to start looking.
The same trace, read as a stack of calls, makes the order obvious. The crash is at the top; each frame underneath is the caller of the one above it:
READ THE TRACE = THE CALL STACK
(top = newest) (who called whom)
▲ validateUser :14 ◀── CRASH ┌─────────────────┐ ▲ start
│ handleSignup :31 │ validateUser 14│ │ looking
│ processTicks... (runtime, ├─────────────────┤ │ here
│ ignore) │ handleSignup 31│ │
│ ├─────────────────┤ │
└─ your code first ──────────────▶│ processTicks... │─┘ (runtime)
└─────────────────┘
read DOWN until the first line that is YOUR file