HomeProjectsBlogContact

How to Read Error Messages and Stack Traces Like a Senior Developer

Error messages look like noise until you know where to look. How to read the message, find your line in the stack trace, decode common errors, and turn a wall of red into a fix.

How to Read Error Messages and Stack Traces Like a Senior Developer

Beginners see a wall of red text and feel stuck. Experienced developers see the same wall and usually know where the problem is within seconds. They're not smarter; they've just learned where to look. You can learn that too, and it'll make you faster than almost any other single skill.

Read the whole first line, slowly

The most important information is almost always at the top: the error type and the message.

TypeError: Cannot read properties of undefined (reading 'map')
    at ProductList (ProductList.jsx:14:22)
    at renderWithHooks (react-dom.development.js:...)
    ...

Translate it into plain words before doing anything else:

  • TypeError: something is the wrong type.
  • Cannot read properties of undefined (reading 'map'): you called .map on something that's undefined.

So the real question is: what was I calling .map on, and why is it undefined? That's already 80% of the debugging.

Find the first line that's your code

A stack trace is a list of function calls, from where the error happened back up through everything that called it. Most lines belong to frameworks and libraries. Skip those and look for the first file you wrote:

at ProductList (ProductList.jsx:14:22)

That's file, line 14, column 22. Go there. In this example, it's probably products.map(...) where products hasn't loaded yet.

A few notes:

  • In Python, the trace reads the other way: the most recent call is at the bottom, right above the error message.
  • In Java and similar languages, look for Caused by: lines. The root cause is often at the bottom of a chain of wrapped exceptions.
  • Minified production traces (a.js:1:28374) need source maps. Upload them to your error tracker so traces point to real files.

A decoder for common errors

Message What it usually means
Cannot read properties of undefined (reading 'x') Something you expected to be an object isn't loaded or doesn't exist yet
x is not a function Wrong import, typo, or the value isn't what you think it is
x is not defined / NameError Variable never declared, out of scope, or misspelled
Unexpected token < in JSON You asked for JSON but got HTML, usually a 404 or error page
Module not found / Cannot find module Wrong path, missing install, or case mismatch in the filename
EADDRINUSE Another process already uses that port
ECONNREFUSED Nothing is listening at that address: service down, wrong host or port
CORS policy Server didn't allow your origin (full explanation)
relation "x" does not exist Table missing: migrations not run, or wrong database
401 vs 403 401: not authenticated. 403: authenticated but not allowed
500 Internal Server Error The real error is in the server logs, not the browser

That Unexpected token < one deserves a special mention. It means the response started with <, as in <!DOCTYPE html>. Your fetch hit the wrong URL and got an HTML page back. Check the Network tab for the actual response.

Errors that lie (a little)

Sometimes the error appears far from the actual cause.

  • The crash is downstream of the bug. A function returned undefined three calls earlier; the error happens where it's finally used. Trace the value backwards.
  • A syntax error points to the wrong line. A missing bracket on line 20 might be reported on line 45, where the parser finally gave up. Look above the reported line.
  • The first error causes the rest. When you see twenty errors, fix the first one and re-run. The others often disappear.
  • A CORS error hides a 500. If the server crashed, it may never have added CORS headers. Check server logs.

Where errors hide

If you don't see an error, you might be looking in the wrong place:

  • Browser console: frontend JavaScript errors.
  • Network tab: failed requests, status codes, response bodies. Click the request and read the response.
  • Terminal running the server: backend errors and stack traces.
  • Hosting dashboard logs: function logs, build logs, runtime logs in production.
  • Database logs: constraint violations, slow queries.

A common beginner trap: the UI shows "Something went wrong," the browser console is clean, and the real stack trace is sitting in the server terminal the whole time.

Search errors effectively

When you need to search, be smart about it:

  1. Copy the error message, minus your specific values. Remove file paths, variable names and IDs.
  2. Add the library or framework name: "Hydration failed" next.js.
  3. Check the date of answers. Fixes for an old version can break a newer one.
  4. Prefer GitHub issues and official docs for library errors. Maintainers often explain exactly what triggers a message.

Write better errors yourself

Once you appreciate a good error message, you'll start writing them:

// Unhelpful
throw new Error('Invalid input')

// Helpful
throw new Error(`Expected "quantity" to be a positive integer, got ${JSON.stringify(quantity)}`)

State what was expected, what you got, and where possible, how to fix it. Your teammates and future self will thank you.

Practice makes it automatic

Next time you hit an error, before searching anything, try this:

  1. Say the error type and message in plain words.
  2. Find the first line of your own code in the trace.
  3. Form a guess about what's wrong.
  4. Check your guess.

Do that a few dozen times and it becomes reflex. Pair it with a systematic process and you'll handle bugs calmly: how to debug code systematically.

FAQ

How do I read a stack trace?

Start with the error type and message, then scan for the first line that references a file you wrote. That's usually where to start. In Python, the most relevant lines are at the bottom.

Why does my error say "undefined"?

You're using a value that doesn't exist yet or was never set: data still loading, a typo in a property name, a function that didn't return anything, or a missing prop.

What does "Unexpected token < in JSON" mean?

Your code tried to parse JSON, but the response was HTML, usually a 404 page or a server error page. Check the request URL and the actual response in the Network tab.

Keep reading

More from the workbench

All articles →