Debugging With AI
Errors are just information. Step through a live example of handing a stack trace to AI and landing on a real fix.
An error message feels like a dead end. It is closer to the opposite — the most specific description of the bug you will get from anywhere, handed to you for free. Step through how a real one gets diagnosed and fixed with AI in the loop.
1. Hit the error
TypeError: Cannot read properties of undefined
at handleSubmit (Form.jsx:24:19)
Questions to ask when debugging
A good bug report to an AI looks a lot like a good bug report to a human. Answer these before you hit send.
- →What's the exact error and full stack trace, if there is one?
- →What did you expect to happen vs. what actually happened?
- →What changed recently, or what input triggers it?
- →Can you share the smallest piece of code that reproduces it?
When each fix creates the next bug
There is a specific way this goes wrong. You paste an error, the AI hands back a fix that sounds right, you apply it, and a different error appears one line downstream. You paste that one too. Three exchanges later you are patching symptoms in a file the original bug never touched, and nobody — you or the model — remembers what the actual problem was.
It happens because each new error looks, to the model, like a fresh and separate puzzle. It reasons about what is in front of it, which is often locally correct and globally wrong: the fix removes the crash without touching the reason the value was wrong in the first place. The cause does not get fixed. It moves.
Stop feeding it, start narrowing it
After two fixes in a row miss, switch modes. Feeding the model another error keeps you moving forward through symptoms; narrowing works backward toward the cause.
- 1
Shrink it to the smallest failing case
Strip the app down to the least code that still reproduces the bug. Understanding every line you keep is usually enough on its own to find it.
- 2
Separate what you know from what you were told
“Cannot read properties of undefined” is a fact. “It's probably the state initialisation” was a guess two fixes ago that turned out to be wrong.
- 3
Check the value directly
A log statement or a debugger breakpoint at the point of failure answers the question instead of theorising about it again.
One printed value ends more of these loops than another prompt does.
- 4
Start a fresh conversation with what you found
Paste the minimal repro and the logged value, not the accumulated thread. A clean context reasons about the real cause instead of defending its last three guesses.
Key takeaways
- An error message is data. Paste the whole thing, not your summary of it.
- Give the AI the trigger, the expectation, and the actual result — the same three things a bug report needs.
- “It says it is fixed” is not the same as fixed. Reproduce the original failure and confirm it is gone.
- Two fixes in a row that each produce a new error is a sign you are drifting from the cause, not closing in on it.
- When you cannot restate the original bug from memory, stop pasting errors and go check a value yourself.
Quick check
Answer these to unlock the next chapter — 3 of 3 to pass. You can retake it anytime.
Answer every question to check.
Make a free account to read on
Every chapter is free — an account is how your progress, XP, and streak follow you from your laptop to your phone, and how you show up on the leaderboard. No payment, no trial.