──────────────────────────────────────

33. The Repair Bench · Follow a Traceback

Read an error name and identify the source line associated with it.

Lesson files · lessons/debugging-and-tests/read-the-traceback

Before you start
- Assign a value to a variable.
- Put a variable into an f-string.

By the end
- Use the last line of a traceback to find the error name.
- Use the listed file and line number to locate the spelling mistake.
- Test the fix by running the same program again.

Where you can use it
Find the cause of a crash after renaming a variable. Use the error type and line number to check where the old spelling still appears.

When Python stops with an error, the traceback shows where the problem came up. Read the last line first for the type of error and its message. Then find the last mention of main.py and use its line number to find the code in the editor.

A NameError means Python could not find a value under a name. Compare the name on the error line with the earlier assignment. Fix one spelling and run the same example again to check the repair.

Predict
Which error would print(singal) produce in the example?
- NameError
- ValueError

Worked example (example.py)

signal = "all clear"
print(signal)


Example result
all clear

Run the broken starter. Read the error, repair the name and make the console print Signal: all clear.

Starter program (starter.py)

signal = "all clear"
print(f"Signal: {singal}")


Hint
Compare the string of letters in the assignment and in the f-string.

Case 1. Try the sample
Input
(No input.)
Expected output
Signal: all clear

Stretch
Make a different spelling error and predict the line the traceback will point to.

Reflect
Write down the final line of the original traceback and what it meant.

Check your prediction
NameError singal has not been assigned. The nearby name signal is spelled differently.
