B · Review & TestIntermediate30 min read
7. Debugging with AI: paste errors, not vibes
AI Coding with Cursor · 44 pages source format
When stuck, paste the exact error, the relevant code, and what you already tried. "It does not work" produces garbage.
What you'll learn
- Error-driven debugging
- Minimal repro
- Iterative fix loops
Error sandwich prompt
Error message + relevant code + expected behavior + what you tried.
## Error
TypeError: Cannot read properties of undefined (reading 'map')
at UserList.jsx:14
## Code (UserList.jsx lines 1-20)
[paste]
## Expected
List renders user names from API response
## Tried
- Added optional chaining on line 14
- Still fails on first render before data loadsDo this now
Take a real error from your terminal. Use the sandwich. Compare to "fix this."
Clear?
Minimal repro
If error persists, ask agent to create the smallest file that reproduces it.
Do this now
Isolate one bug to a single-file repro with agent help.
Clear?