AI-Assisted Troubleshooting
When to Call in AI for Help
In Lesson 5.2, you learned to debug systematically: describe the problem, narrow it down, change one thing at a time. Sometimes that's enough. But other times you'll hit a wall — the bug is in unfamiliar code, the error message is cryptic, or you've tried everything you can think of.
That's when AI becomes your debugging partner. AI is excellent at translating error messages, explaining what code does, suggesting fixes, and thinking through problems step by step. The key is knowing how to describe the problem so AI can actually help.
Answer: Try to understand the problem yourself first — that builds your skills. Use AI when you're stuck after a few minutes, when the error message is confusing, or when the bug is in code you don't understand. AI is a debugging partner, not a replacement for thinking.
The Perfect Bug Report for AI
The quality of AI's debugging help depends entirely on how well you describe the problem. Here's the template that works:
- What you were trying to do: "I'm building a streak counter that increases when a habit is checked off."
- What you expected to happen: "When I click the checkbox, the streak number should go up by 1."
- What actually happens: "Nothing changes. The number stays at 0 no matter how many times I click."
- What you've already tried: "I checked the HTML and the checkbox exists. I added console.log and it's not printing anything when I click."
- The relevant code: [paste the specific section, not the entire project]
This pattern gives AI everything it needs to diagnose the issue. Compare this to "my code doesn't work, fix it" — which would produce a generic, probably unhelpful response.
Error Messages Are Your Friends
Error messages look scary, but they're actually the most helpful debugging tool you have. They tell you exactly what went wrong and often where.
When you see an error message, do these things:
- Read it. Don't skip it because it looks technical.
- Look for the file name and line number. This tells you where the error is.
- Look for the error type. Common ones: "TypeError" (wrong data type), "ReferenceError" (trying to use something that doesn't exist), "SyntaxError" (the code has a typo or structure problem).
- If you don't understand it, paste the exact error message into AI and ask: "What does this error mean in plain language, and what typically causes it?"
Pro tip: Copy the exact error message, not a paraphrase. AI can search for known patterns in error messages. "Uncaught TypeError: Cannot read property 'length' of undefined" is far more useful than "there's a type error."
When AI Sends You in Circles
Sometimes AI's suggested fix doesn't work. You try it, get a new error, ask AI about that, try the new fix, get another error... This is called a debugging loop, and it's a sign you need to change approach.
When this happens:
- Stop. Don't keep trying AI's suggestions if they're not converging on a solution.
- Revert to the last version that worked. Undo all the failed fixes.
- Start a fresh conversation. The old conversation's context is probably confused.
- Reframe the problem. Instead of "fix this error," try: "Explain what this code is supposed to do and identify any logical problems."
- Simplify. Can you solve the problem with a simpler approach? Sometimes the fix is to rewrite the component more simply rather than patching complicated code.
Key Concepts
- Use AI for debugging when you're stuck, error messages are confusing, or the bug is in unfamiliar code.
- The bug report template: what you tried to do, expected behavior, actual behavior, what you've tried, relevant code.
- Error messages contain valuable information: file/line number, error type, and description. Paste them exactly.
- When AI's fixes create more problems: revert, start fresh, reframe the problem, or try a simpler approach.
- Always ask AI to explain its fix, not just provide one. Understanding prevents the same bug from recurring.
Find the Bug Report Template and all other downloadable resources on the Dashboard Resources page.
Level Up: Coming Next
Lesson 5.7 — Deployment: Making It Real. Get your finished project on the internet where real people can use it.
Continue to Lesson 5.7 →