Predict

The Scene of the Crash

When a program crashes, Python leaves a traceback: a trail of clues showing which calls were running when things went wrong.

Read it like a detective, from the bottom up:

  1. The last line names the error type and gives a message.
  2. The frames above it list each call, oldest at the top, newest at the bottom. Each frame shows a file, a line number and the function it was in.
  3. Find the lowest frame in your file. Frames in Python's own files (like json/decoder.py) show where the problem surfaced. The cause is almost always in your code.

Python 3.11 and newer also draw ~~~^^^ marks under the exact part of a line that failed.

Pip tip: Python's own libraries are very well tested. If the crash ends inside one, ask: "What did my code hand it?"

Traceback (most recent call last):
  File "main.py", line 14, in <module>
    save = load_save(raw)
  File "main.py", line 6, in load_save
    data = json.loads(text)
  File "/lib/python3.14/json/__init__.py", line 352, in loads
    return _default_decoder.decode(s)
  File "/lib/python3.14/json/decoder.py", line 345, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/lib/python3.14/json/decoder.py", line 363, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The quest-save loader crashed. Which line should the detective inspect first?