AI Development

How to Read a Stack Trace

The error report your computer shows when something goes wrong — and how to actually understand it.

Scroll to start

What Is a Stack Trace?

Imagine you drop a plate in a busy kitchen. The chef yells, "Who was carrying plates near the stove?" — but really the plate broke because someone bumped the table, and someone else left the floor wet, and someone else stacked plates too high. One thing broke, but many things contributed.

A stack trace is your computer's way of telling that same story when your code crashes. It shows you the exact path your program was following when it hit a problem. Every step that led to the crash is listed, newest to oldest.

When your code breaks, instead of just saying "something went wrong," the computer prints a big wall of text. Most people see all that text and panic. But once you know what to look for, it's actually a helpful map.

Errors Are Your Friend

When you're learning to code, seeing a big red error feels terrible. It feels like you did something wrong. But professional developers see errors as the computer trying to help. The error message is the computer saying, "I can't do this one thing — here's exactly where I got stuck."

Reading a stack trace quickly is one of the skills that separates someone who fixes a bug in five minutes from someone who sits stuck for hours. The error tells you where the problem is, what went wrong, and sometimes even why. You just have to know how to read it.

💡 Key Insight

Most beginners look at an error and feel bad. Experts look at an error and feel curious. "What happened here?" is a better question than "I did this wrong."

Anatomy of a Stack Trace

A stack trace has a few key parts. Here's what each one means:

a real stack trace
TypeError: Cannot read property 'name' of undefined
    at greetUser (hello.js:6:15)
    at main (index.js:3:5)
    at Module._resolveFilename (internal/modules/cjs/loader.js:1171:30)

🔍 The Key Parts

1.
The error message — "Cannot read property 'name' of undefined" — tells you what went wrong. Code tried to read something's name, but that something was empty.
2.
The first file:line listedhello.js:6:15 — tells you exactly where the crash happened. This is usually the only line you need to look at first.
3.
The "called at" lineat main (index.js:3:5) — tells you who called the crashing code. In our example, the main function called the greetUser function that broke.
4.
Everything below — internal node/module lines — is machinery underneath. You usually don't need to look at these unless you're building tools yourself.

Reading a Real Error

Let's say you run your code and this appears:

terminal output
ReferenceError: message is not defined
    at showMessage (app.js:12:4)
    at handleClick (buttons.js:8:3)
    at HTMLButtonElement.onclick (index.html:1:1)

Here's how to read it step by step:

  1. Read the error messagemessage is not defined. The code tried to use a variable called message, but that variable doesn't exist yet.
  2. Go to the listed fileapp.js, line 12. That's where the code tried to use message.
  3. Check who called ithandleClick in buttons.js line 8 called the code that broke.
  4. Fix it — Make sure message is defined before line 12 runs. Maybe you forgot to set it, or spelled the name wrong.

That's the whole process: find the error, go to the file and line, check your variable.

Knowledge Check

Test what you learned with this quick quiz.

Quick Quiz — 3 Questions

Question 1
What does a stack trace show you?
Question 2
When you see a stack trace, which line should you look at first?
Question 3
If you see "Cannot read property 'title' of undefined," what should you do first?
🏆

You crushed it!

Perfect score on this module.