VCA

When AI's code breaks: a debugging primer

AI-generated code isn't always right the first time. Read the error, narrow it down, feed the right clues back to the AI — a systematic way for beginners to debug.

Published Updated Reviewed 2 min readEditorial policy#Guide#Debugging#AI collaboration

In one sentence

Debugging isn't guessing — it's narrowing down and feeding the right clues back to the AI. Learn this and the AI can actually fix it.

What you'll build

A fixed routine for broken code: how to read the error, narrow the range, and give the AI the clues it needs to fix it.

Breaking is normal

AI-written code isn't always right the first time — that's not on you, it's normal. The difference is that people who can debug get it fixed, while those who can't just keep telling the AI to "try again" and make it messier. Debugging is a learnable, systematic method, not inspiration.

Step 1: read the error message (don't skip it)

When something breaks, the screen or the browser's Console usually shows a red error. The most common beginner mistake is to panic at the red text and immediately paste it to the AI saying "it's broken." Read it first: the error often tells you exactly which file, which line, what problem. Not understanding it is fine — but capture it in full.

Step 2: narrow it down (bisection)

Don't stare at the whole program at once. Ask: "When did it last work? What did I change?" Cut the suspect range in half — remove or comment out a suspicious section and see if it still breaks. Once you can reproduce it reliably in a small range, it's easy to catch.

Step 3: feed the right clues back to the AI

When the AI can't fix it, it's usually because you gave it too little. Give all three at once and the hit rate jumps:

  • The full error message (the whole thing, not "it broke").
  • Reproduction steps: what you did to trigger it, what you expected, what actually happened.
  • What you've already tried: so the AI doesn't repeat what already failed.

Common traps

  • Changing too much at once: when it breaks, you can't tell which change caused it. Change one thing, then test.
  • Not opening the Console: many errors only show in the console while the screen "just looks off."
  • Endless "try again": when the AI can't fix it repeatedly, step back, narrow it yourself, and give fresh clues — that beats retrying.

Next steps

Frequently asked questions

What if the AI keeps failing to fix the same bug?

Don’t fall into endless "try again." Step back and narrow it down yourself (bisect to find the offending section), then give "the full error + reproduction steps + what you’ve tried" all at once. The more specific the info, the better the AI does; "still broken" almost guarantees going in circles.

Can I debug if I can’t understand the error message?

Yes. You don’t have to understand every word, but capture the **full** error and give it to the AI — it usually can. Often more useful than the error itself are the reproduction steps: "what triggers it, what you expected, what happened." Give those together for the best hit rate.

References

  1. Chrome DevToolsGoogle
  2. JavaScript error reference — MDNMozilla