Lesson 31 of 1570
Debugging With AI Help
Bugs are where AI is most useful and most humbling. Paste errors, ask for causes, run experiments, and learn how to get a real answer instead of a guess.
Lesson map
What this lesson covers
Learning path
The main moves in order
- 1The Paste-and-Ask Pattern
- 2debugging
- 3stack trace
- 4minimal reproduction
Concept cluster
Terms to connect while reading
Section 1
The Paste-and-Ask Pattern
The most common debugging move with AI is: paste the error message, paste the code around it, describe what you expected, and ask why. This works shockingly often because stack traces contain rich clues that the AI has seen a thousand times.
What to paste, in order
- 1The exact error message, including the last few lines of the stack trace
- 2The function that triggered it, with line numbers if possible
- 3The input you gave, if any
- 4A one-sentence summary of what you expected
A real-looking debug conversation
Notice how the AI does not blindly fix — it proposes hypotheses and a test. That's the right pattern.
Me:
I'm getting this error in my Node.js script:
TypeError: Cannot read properties of undefined (reading 'map')
at loadUsers (index.js:14:22)
My code at line 14 is:
const names = response.data.users.map(u => u.name);
I'm calling a REST API and expected an array of users.
AI:
The error means response.data.users is undefined at the moment you
call .map. Two likely causes:
1. The API returned an error shape, like { error: "unauthorized" },
instead of { data: { users: [...] } }.
2. The response structure is different — maybe it's just { users: [...] }.
Add this log before line 14 to find out:
console.log(JSON.stringify(response.data, null, 2));When AI is great at debugging
- Syntax errors and typos
- Common library errors with famous stack traces
- Explaining what an unfamiliar error message means
- Turning a vague bug into a list of hypotheses
When AI is bad at debugging
- Bugs in logic that look correct line by line
- Issues caused by data it cannot see
- Bugs that only appear in production
- Timing and concurrency problems
The rubber-duck bonus
Sometimes explaining the bug to the AI in full sentences is enough to make you spot it yourself. That is called rubber-duck debugging and it is one of the best side effects of working with an AI partner.
“If you cannot explain the bug to the AI, you do not understand it yet.”
Key terms in this lesson
The big idea: AI is a great debugging partner when you paste the right information and ask why before fix. Shrink the problem, share the evidence, and guide the conversation toward the root cause.
End-of-lesson quiz
Check what stuck
15 questions · Score saves to your progress.
Tutor
Curious about “Debugging With AI Help”?
Ask anything about this lesson. I’ll answer using just what you’re reading — short, friendly, grounded.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Builders · 45 min
Your First Capstone — Ship a Small Project
Bring it all together. Pick one of three starter projects, plan it, build it with AI, and deploy it. You are now a builder who ships.
Builders · 25 min
What Does AI-Assisted Coding Even Mean?
AI-assisted coding is not magic and not cheating. It is a new way of working where a model drafts, you decide. Let's draw a map before we start building.
Builders · 30 min
Your First Copilot-Style Completion
Let's actually feel what autocomplete is like. Write a comment, pause, and watch a full function appear. Then learn what to do next.
