Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Reading errors and finding fixes

After this lesson: I can read an error message and find the fix.

50 min lessonNo commands

Twelve lines of red text

The nightly sales report did not arrive. Your manager forwards you the error: twelve lines of red text.

It looks frightening. But most of those lines are a route map, and one line holds the answer.

Reading errors calmly is a skill every technical job uses daily.

By the end of this lesson

Note

I can read an error message and find the fix.

Key words

WordWhat it meansExample
Error messagetext a program prints when it cannot go on
Tracebackthe list of steps Python took before the error
Exceptionthe named kind of errorTypeError
Documentationthe official guide to a tool or language
SSHa safe way to open a terminal on another computer

The cells students fill in are left blank in this preview.

Read a traceback from the bottom

In Python, the last line of a traceback names the exception and says what went wrong.

The line just above it gives the file and the line number where it happened.

The lines higher up show the route the program took to get there. Read them only if the bottom is not enough.

Make an error and read it

Code: python
# The report prints how many orders came in today.
orders_today = 12

# Run this. Read the LAST line of the error first.
message = "Orders today: " + orders_today
print(message)

# Fix it: turn the number into text with str(orders_today).

Worked example: errors you will meet

Last line starts withWhat it usually means
NameErrorA name is misspelt or not made yet
TypeErrorTwo kinds of value were mixed, such as text and a number
KeyErrorA dictionary has no such key
FileNotFoundErrorThe path is wrong, or you are in the wrong folder
ZeroDivisionErrorSomething was divided by 0
ModuleNotFoundErrorA library is not installed

The cells students fill in are left blank in this preview.

A common mistake

Warning

Many people think the first red line is the cause, so they fix the wrong place. In a Python traceback the cause is at the bottom. Read the last line, then the line number just above it.

Search with the exact message

Copy the exception and its message into a search. Leave out your own file names and numbers.

Look at the official documentation first. It is written by the people who made the tool.

Check that the page matches your version. An answer for an old version can be wrong for yours.

A good question gets a quick answer

If you are stuck after twenty minutes, ask a colleague. Say what you were trying to do and what you expected.

Then say what happened, with the full error message, and what you have tried.

Never paste a password, a key or a customer's details into a question.

Worked example: two ways to ask

A poor questionA good question
The report is broken.The nightly report stops with KeyError: price on line 14.
It does not work.I expected a total. I got the error below.
Can you fix it?I checked the JSON, and some orders have no price. Should they?

The cells students fill in are left blank in this preview.

SSH takes you to the server

Often the error happened on a server, not on your laptop. SSH opens a terminal on that server over the network.

You type ssh and a user name and host, such as ssh [email protected]. Then the commands you know work there: cd, ls and grep.

Finding the error on a server

Code: bash
$ ssh [email protected]
sam@reports:~$ cd /var/log/reports
sam@reports:/var/log/reports$ grep ERROR nightly.log
2026-10-21 02:00:14 ERROR KeyError: 'price'
sam@reports:/var/log/reports$ exit
logout
Connection to reports.shop.example closed.

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.