Home / Emergency Rescue / Reading Python Tracebacks
Lesson 1 of 5

Reading Python Tracebacks

Concept

When Python crashes, it prints a traceback — a stack of function calls showing exactly where and why it failed. Read it bottom to top: the last line is the actual error, the lines above show how the code got there.
Real traceback from a mesh crash
Traceback (most recent call last):
  File "/app/app/main.py", line 245, in dispatch_handler
    result = await dispatch_task(task_data)
  File "/app/app/dispatch.py", line 180, in dispatch_task
    agent = await db.get_best_agent_for_capability(cap)
  File "/app/app/db.py", line 3520, in get_best_agent_for_capability
    return random.choice(candidates)
IndexError: Cannot choose from an empty sequence

What's happening

Reading bottom-up: IndexError is the error type. random.choice(candidates) failed because candidates was empty — no agents were available. The call chain: main.py called dispatch.py called db.py. The file paths and line numbers tell you exactly where to look.

Quick Check — 3 questions

1. Where in a traceback is the actual error?

2. What does File "/app/app/db.py", line 3520 tell you?

3. What does IndexError: Cannot choose from an empty sequence mean?