Lesson 8 +15 XP

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:

  1. The Code: The relevant snippet where the error occurs.
  2. The Full Stack Trace: Copy-paste the exact error traceback.
  3. 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).