๐Ÿ›
๐Ÿ› Debugging & Problem-Solving ยท DEBUG-101 ยท Session 2 of 6

Read the Error Message

The error message is trying to tell you exactly what went wrong and where โ€” but only if you actually read it. Learning to decode a traceback is a superpower most beginners skip.

โฑ 9 min read๐Ÿ“… Updated 2026-07-30๐Ÿ“Š Tables, charts & examples

Beginners' most common debugging mistake is astonishingly simple: they don't read the error message. They see red text, panic, and start changing things at random. But that error message is a precise report of what went wrong and where - often it tells you the answer directly. This session teaches you to actually read it: the traceback, the error type, and the line number.

๐Ÿ“Œ Worked example
The answer was in the message all along. A learner spent forty minutes rewriting a function that 'didn't work', trying change after change, growing more frustrated. When they finally read the red text at the bottom of the traceback, it said NameError: name 'lenght' is not defined - they'd typed 'lenght' instead of 'length', and the error had been naming the exact typo, on the exact line, the entire time. Forty minutes of guessing versus ten seconds of reading. It's the most common debugging lesson there is: the error message is usually trying to hand you the answer - read it first.

Anatomy of an error

A Python error (a 'traceback') has three parts worth reading: where it happened, what type of error, and a message. Read from the bottom up.

Traceback (most recent call last):
  File "shop.py", line 12, in <module>
    total = price * quantitiy
NameError: name 'quantitiy' is not defined
๐ŸŽฏ
Read the last line first - it names the problem. The bottom line here says NameError: name 'quantitiy' is not defined - a typo (quantitiy). Right above it, the traceback shows the exact file and line (line 12) and the code involved. That's the whole answer: what went wrong (an undefined name), where (line 12), and the clue (a misspelling). The error didn't just fail - it told you precisely where to look and what to fix.

Common error types, decoded

A handful of error types cover most of what you'll meet. Recognising them tells you what kind of mistake to look for.

Error typeUsually means
NameErrorA typo, or using something before defining it
TypeErrorWrong kind of value (e.g. adding text to a number)
IndexError / KeyErrorAsking for an item that isn't there
SyntaxErrorThe code isn't valid Python (missing :, ), quote)
IndentationErrorWrong or inconsistent indentation

You don't need to memorise these - just know the error type is a strong hint about the category of mistake. 'TypeError' points you at values and types; 'KeyError' points you at a dictionary key that's missing. The type narrows your search enormously.

Let the error guide you

  • Actually read it - most beginners skip this and change things at random.
  • Read the last line first - it names the error type and the problem.
  • Use the line number - the traceback points at exactly where to look.
  • The error type is a hint - NameError = typo, TypeError = wrong value, KeyError = missing key.

๐ŸŽฏ Key takeaways

  • The most common beginner mistake is not reading the error message - which usually contains the answer.
  • A traceback tells you three things: where it happened (file/line), the error type, and a message.
  • Read the last line first - it names the error type and describes the problem.
  • The error type is a strong hint: NameError = typo, TypeError = wrong value, KeyError/IndexError = missing item.

Frequently asked

The traceback is long and confusing - which part do I actually look at?

Start at the very bottom and work up - that's the key trick that makes tracebacks far less intimidating. The last line is the most important: it states the error type (like NameError or TypeError) and a message describing what went wrong, which is often the answer or very close to it. Just above that, the traceback shows the exact file and line number where the error occurred, along with the offending line of code - so you know precisely where to look. The middle of a long traceback shows the chain of function calls that led there (function A called B, which called C, where it broke); early on you can usually ignore that chain and focus on the bottom, because the failure is at the deepest point. As a rule: read the last line (what and why), then the line number just above (where), and go fix that spot. Only dig into the earlier call chain if the fix isn't obvious at the failure point and you need to understand how the code got there. The length is intimidating, but the two or three lines at the bottom carry almost all the useful information.

What if I read the error message and still don't understand it?

That's normal and fine - understanding error messages is itself a skill that grows, and there's a reliable next step: search for it. Copy the error type and message (like 'TypeError: can only concatenate str (not int) to str') and paste it into a search engine. Because millions of programmers have hit the same errors, you'll almost always find clear explanations and examples - often on sites like Stack Overflow - of what that error means and what typically causes it. This isn't cheating or a sign of weakness; looking up errors is something professional programmers do constantly, every single day. As you do it, you'll gradually build an intuition for common errors and need to search less. A good process is: first read the error carefully and look at the line it points to (often that's enough); if it's still unclear, search the exact message; and if you're still stuck, simplify the situation (which the next sessions cover) to see the error in isolation. The message plus a search engine resolves the large majority of errors, even ones that look baffling at first. Not understanding an error immediately is expected - knowing how to find out is the actual skill.

Session 2 of 6 complete

Next up: Print, Trace, and See What's Happening

Continue to Session 3 โ†’

Related lessons

More in this course

Course home → · Browse all courses →