Error Messages, Stack Traces and Logs

2.The Note, the Footprints and the Diary

A

In this chapter

We'll learn to read the three things a program leaves behind when something goes wrong — error messages, stack traces and logs — like a detective reading a note, a trail of footprints and a diary.

12–14 min

The Problem in Real Life

John opens the production logs and filters them to the Riverside Arena event page. Most lines are calm: requests, response times. But Anna spots a red block in the middle of them: TypeError: Cannot read properties of null (reading 'name'), followed by eight lines that start with "at".

"Is that our bug?" she asks. John smiles. "Read it and tell me. Error messages look scary, but they're the most honest thing in the whole system. They tell you exactly what went wrong and exactly where."

A

I always just scrolled past the red text.

Anna

Panicking at Red Text vs. Reading It Like a Clue

Error messages look scary

Beginners scroll past them. But the answer is very often written right there.

Stack traces look like noise

Eight lines of file names and numbers — until you know which line to read first.

Logs are huge

Thousands of lines a minute. You need to know how to filter them to find the clue.

Error Messages, Stack Traces and Logs

The detective analogy: at a crime scene, a detective reads three things. A note left behind (what happened), a trail of footprints (how the person got there, step by step) and the house's diary (everything that happened that day, in order). A program leaves the same three things: an error message, a stack trace and logs.

  • Error message — the note: an error message has two parts: the type of error and the description. In TypeError: Cannot read properties of null (reading 'name'), the type is TypeError (something was the wrong type — here, null instead of an object) and the description says the code tried to read .name from something that was null. In plain English: "you asked for the name of a thing that doesn't exist."
  • Stack trace — the footprints: a stack trace is the call stack (Act 10) at the moment of the error: the chain of function calls that led there, newest first. Each line says the function, the file, the line number and the column. Read the top line first — that's where the error happened. Then walk down to find the first line from your own code (not from a library or node_modules) — that's usually where to start looking.
  • Logs — the diary: logs are messages a program writes while it runs (Act 06): requests, warnings, errors, start-up information. Each line usually has a time, a level and a message. Levels tell you how serious it is: DEBUG (fine details for developers), INFO (normal events), WARN (something odd but handled), ERROR (something failed).
  • Filtering logs — finding the right page of the diary: production logs can be thousands of lines a minute. You narrow them down: by time (when the bug was reported), by level (only WARN and ERROR), by text (the event ID, the URL, a user ID). Every log tool, and even grep in the terminal (Act 06), can do this.
Table — Common error messages in plain English
Error messagePlain EnglishCommon cause
TypeError: Cannot read properties of null (reading 'x')You asked for x of a thing that doesn't existMissing data, unchecked null
ReferenceError: total is not definedYou used a name that was never createdTypo, wrong scope (Act 07)
SyntaxError: Unexpected token }The grammar is broken hereMissing or extra bracket
ECONNREFUSED 127.0.0.1:5432Nothing is listening on that portDatabase not running (Act 11)
ENOENT: no such file or directoryThat file isn't thereWrong path, missing file
Table — Log levels
LevelMeaningExample
DEBUGFine details for developersformatShowTime input=2026-11-14T20:00:00Z
INFONormal eventsserver started TZ=Europe/Berlin
WARNOdd, but handledpayment API slow: 2.4s
ERRORSomething failedTypeError in formatShowCard

Reading a stack trace, top to bottom

TypeError: Cannot read properties of null (reading 'name')

the note: what went wrong

called by

at formatShowCard (src/events/format.js:42:28)

where it happened — read this first

called by

at renderEventPage (src/events/page.js:17:10)

who called it — still our code

at ... (node_modules/...)

framework code — usually skip

The red block in the logs
2026-11-12T10:41:07Z ERROR TypeError: Cannot read properties of null (reading 'name')
at formatShowCard (src/events/format.js:42:28)
at renderEventPage (src/events/page.js:17:10)
at handle (node_modules/framework/router.js:211:9)
at next (node_modules/framework/router.js:180:3)
...

Top line first: the error happened at line 42 of format.js. The node_modules lines are the framework — not where the bug is.

Filtering logs in the terminal
grep "ERROR" app.log # only the errors
grep "event=riverside-arena-1114" app.log # only this event
grep "server started" app.log # when (and how) the server started

Reading Anna's stack trace: the top line is at formatShowCard (src/events/format.js:42:28) — the error happened in the formatShowCard function, file format.js, line 42. Line 42 is venue.name. So venue was null. The second line shows it was called from renderEventPage. The other lines are inside the web framework — not our code. The cause: a test show created by the marketing team has no venue yet. It's a real bug — but not the hour bug. It's a runtime error; the hour bug never crashes.

One bug at a time: Anna writes a separate ticket for the null venue (with the full stack trace pasted in) and goes back to the hour bug. Mixing two bugs in one investigation is a classic way to fix neither.

The real clue was an INFO line: scrolling up to when the server last started, she finds: INFO server started region=eu-central-1 TZ=Europe/Berlin. Her own laptop's timezone is Europe/London. Berlin is one hour ahead of London. She writes it in the ticket with a question mark. It's a clue, not proof yet.

Key Takeaway

Read what a program leaves behind like a detective. The error message is the note: its type and a plain description of what went wrong. The stack trace is the footprints: read the top line first, then find the first line from your own code. Logs are the diary: filter them by time, level and text. Clues often hide in normal INFO lines, not just errors — and investigate one bug at a time.

Why This Matters

Most bugs announce themselves through an error message, a stack trace or a log line — and the answer is very often right there for anyone who reads carefully. Being the person on the team who actually reads the red text, slowly, saves hours. And knowing how to filter logs is essential once your code runs on servers you can't touch directly.

"TZ=Europe/Berlin" is a clue, not proof. John wants Anna to see the bug happen with her own eyes — inside the function, value by value. Time to use the debugger she set up in Act 16.