Loading lessons...
Debugging Stack Traces & Refactoring Code
Fixing Bugs in Record Time
Instead of staring at a cryptic stack trace for hours, you can feed error logs directly into an LLM.
Anatomy of a Debugging Prompt
To get the most accurate fix, provide 3 key pieces of information:
- The Code: The relevant snippet where the error occurs.
- The Full Stack Trace: Copy-paste the exact error traceback.
- The Expected vs Actual Behavior: What was supposed to happen vs what failed.
I am getting a TypeError in my React component:
Error: Cannot read properties of undefined (reading 'map')
Code:
function UserList({ users }) {
return <ul>{users.map(u => <li key={u.id}>{u.name}</li>)}</ul>;
}
Explain WHY this error occurs and provide a defensive fix.
Note
AI will identify that users might be undefined during initial render and suggest default props (users = []) or optional chaining (users?.map).