Read Error Messages Without Panic
A wall of red text is one of the most discouraging things a new programmer sees. It looks like the computer is angry. It is not. An error message is the most helpful thing your program can give you: it tells you what went wrong and where.
Many beginners copy the whole error into an AI chat without reading it. That works sometimes, but you learn nothing, and you cannot tell if the AI's fix makes sense. This lesson teaches you to read errors yourself in under a minute. Then AI becomes a helper, not a crutch.
What You'll Learn
- The parts of an error message and which line to read first
- How to read a Python traceback and a JavaScript error
- The most common error types and what they usually mean
- How to fix your first bug using only the error message
Read the last line first
Here is a typical Python error:
Traceback (most recent call last):
File "shop.py", line 4, in <module>
total = total + prise
NameError: name 'prise' is not defined
Beginners often start reading at the top. Start at the bottom instead. The last line has two parts:
- The error type:
NameError. This tells you the category of problem. - The message:
name 'prise' is not defined. This tells you the specific problem.
Then look just above it for the location: line 4, and the exact code on that line: total = total + prise.
In ten seconds you know: on line 4, Python does not recognize the name prise. Most likely a typo for price.
- 1. Last lineError type and message: what went wrong
- 2. Line aboveFile, line number, and code: where
- 3. Go to that lineLook at the names and values used there
Tracebacks show the path
When code calls functions that call other functions, the error shows every step that led to the problem. This list is called a traceback in Python or a stack trace in JavaScript.
- In Python, the most recent step is at the bottom, right above the error.
- In JavaScript, the error is at the top, and the lines below show where it came from, most recent first.
In both languages, the most useful location is usually the first line that points to your own code, not to a library or built-in file. Skip past lines that mention files you did not write.
A JavaScript example:
ReferenceError: prise is not defined
at calculateTotal (shop.js:4:23)
at shop.js:9:1
Same bug, different layout: error type and message on top, then shop.js line 4, column 23.
Common error types
You will see the same few types again and again. Learning them is half of debugging.
The error type narrows the search before you read a single line of code.
| Criteria | Python | JavaScript | Usually means |
|---|---|---|---|
| Unknown name | NameError | ReferenceError | A typo, or using a variable before creating it |
| Wrong kind of value | TypeError | TypeError | Mixing text and numbers, or calling something that is not a function |
| Position does not exist | IndexError | (no error, gives undefined) | Going past the end of a list |
| Missing key | KeyError | (no error, gives undefined) | Asking a dictionary or object for a key it does not have |
| Nothing there | AttributeError on None | TypeError: cannot read properties of undefined | A value you expected is empty |
| Code not valid | SyntaxError | SyntaxError | Missing bracket, colon, or quote |
Python
- Unknown name
- NameError
- Wrong kind of value
- TypeError
- Position does not exist
- IndexError
- Missing key
- KeyError
- Nothing there
- AttributeError on None
- Code not valid
- SyntaxError
JavaScript
- Unknown name
- ReferenceError
- Wrong kind of value
- TypeError
- Position does not exist
- (no error, gives undefined)
- Missing key
- (no error, gives undefined)
- Nothing there
- TypeError: cannot read properties of undefined
- Code not valid
- SyntaxError
Usually means
- Unknown name
- A typo, or using a variable before creating it
- Wrong kind of value
- Mixing text and numbers, or calling something that is not a function
- Position does not exist
- Going past the end of a list
- Missing key
- Asking a dictionary or object for a key it does not have
- Nothing there
- A value you expected is empty
- Code not valid
- Missing bracket, colon, or quote
Notice that JavaScript often does not raise an error where Python does. Instead it quietly gives undefined, and the problem shows up later as a strange result. That makes some JavaScript bugs harder to find, which the next lesson helps with.
A tip for SyntaxError: the line number points to where the language noticed the problem, which can be just after the real mistake. If the line looks fine, check the line before it for a missing bracket, colon, or quote.
Your turn: fix it from the error
Run the code below. Read the error message, find the line, and fix the bug. The correct output is Total: 13.75.
You just debugged without any AI. That skill is what makes AI help useful later: you can check whether a suggested fix actually matches the error.
Key Takeaways
- An error message is helpful information, not a verdict on your ability.
- Read the last line first in Python (error type and message), then the location just above it.
- In JavaScript, the error is at the top of the stack trace, with locations below.
- Focus on the first location in your own code, and skip lines from libraries.
- Learn the common types (NameError/ReferenceError, TypeError, IndexError, KeyError, SyntaxError). The type narrows the search immediately.

