Reading an Error Message: A Method

A calm, repeatable method for reading error messages and stack traces: what the type, location and message tell you, how to find your own code in the trace, and what to do next.

Free preview · 2 of 3 free left
Topic: Troubleshooting Guide beginner 6 min read

Why this matters

Most beginners see a wall of red text and feel the same thing: panic, then guessing. But an error message is the computer telling you, as exactly as it can, what it expected and what it found. The skill is not knowing every error. It is reading the message in the same calm order every time.

What you'll learn

The three parts every error message has, where to look in a stack trace, a seven-step method for what to do next, and how to ask for help in a way that gets quick answers.

The three parts of an error

Take this small program:

age = 25
print("Hello, " + age)

Python stops with:

Traceback (most recent call last):
  File "greet.py", line 2, in <module>
    print("Hello, " + age)
TypeError: can only concatenate str (not "int") to str

(Newer versions of Python also print ~~~^ marks under the exact spot.) Read those three and you already know the fix: turn the number into text with str(age). The message was the answer.

Where to look in a stack trace

A stack trace lists the calls that led to the failure. The order depends on the language. Python prints the oldest call first and the failure last, so the final line is the one to read first. Node.js prints the message first and then the calls, with the most recent on top. In either, one rule holds: find the first line that points into your own files. Lines pointing into libraries show the path of the failure, but your mistake is almost always in your code, one step before the library complained.

The seven-step method

  1. Read all of it, slowly. Not the first word; every word.
  2. Name the type. What category of failure is this (type, name, file not found, connection refused)?
  3. Find your line. The first file path that is yours, with its line number.
  4. Say what you expected and what you got. Out loud or in writing. Many bugs disappear at this step.
  5. Make it small. Remove everything that is not needed until the smallest program that still fails remains.
  6. Search with the message, not your story. Copy the error text, remove your own file paths and names, and search for that. Others have met it before you.
  7. Change one thing at a time. If you change three things and it works, you do not know which one fixed it, so you learn nothing.

Ask for help properly

When you ask a teacher, a colleague or a forum, give four things: what you were trying to do, the exact error text (copied, not a screenshot of part of it), the smallest code that shows it, and what you have already tried. A question like that is usually answered in minutes, because the person helping can see the same thing you see.

Try it yourself

Write the two-line program above, run it, and fix it. Then break it again on purpose in three different ways: misspell print as pritn, delete a closing bracket, and open a file called nothing.txt that does not exist. For each, find the type, the location and the reason, using only the message. Notice how each error names a different kind of mistake.

What's next

When errors come not from your own program but from a server writing logs, read Reading Logs Backwards. To go from "what broke" to "why it broke", read Root Cause Analysis Framework. If you are just starting out, Your First Program: Understanding Before Memorizing comes first.

Continue learning

Guide

Reading Logs Backwards: A Debugging Habit

Why reading logs from the moment of failure backward, instead of scrolling forward from an arbitrary starting point, is faster and catches the real cause more reliably.

Guide

Root Cause Analysis: A Simple Framework

A practical, repeatable framework for finding a real root cause instead of stopping at the first plausible explanation — the Five Whys, contributing-vs-root-cause, and writing a blame-free postmortem.

Guide

Your First Program: Understanding Before Memorizing

Why memorizing syntax is the slow road and understanding what each line does is the fast one — how to read your first programs so the knowledge sticks.

← Back to Guides

Next → Reading Logs Backwards: A Debugging Habit Why reading logs from the moment of failure backward, instead of scrolling forward from an arbitrary starting point, is faster and catches the real cause more reliably.