#173 AI coding and productivity 6.6 min
Debug with AI: Give It a Traceback and a Minimal Repro
Eight rows crashed a report; a small shrink found the one row and a 5-line repro.
Fix the bad row and run the report
Copy the code folder first. In buggy.py, find the row whose quantity is the text "3" and change it to the number 3, without quotes. Predict what python buggy.py prints, then run it. When I ran it, it printed: average unit price: 4.0
A hint
Only row 5 has a quantity in quotes.
Run the shrink with no crash to find
With the fixed buggy.py from the first exercise, run python run.py. Predict what happens, because the tool expects a real traceback to work from. Read the last line of what it prints and say why it stops. When I ran it, it stopped with an IndexError.
A hint
run.py keeps the last line of the traceback, and a clean run has no traceback.
Predict which row the shrink keeps
Put the text back in row 5 ("3"). Then also make row 8 a text quantity, "6" in quotes. Predict which row the shrink keeps and which error the last refused cut gives, then run python run.py and compare. When I ran it, it kept the row with quantity '6' and total 15.0, and one refused cut gave a ZeroDivisionError.
A hint
The shrink drops rows from the start, one at a time, and keeps a cut if the same error remains.
Change the bug and write your own expected line
Set the bad row back to the original, then change its quantity to the number 0 instead of text. Predict the new error name, then run python run.py and check it. When I ran it, the error was ZeroDivisionError: float division by zero. Then open bundle.py, change the EXPECTED text to a sentence of your own, and run python run.py bundle to see it under the Expected heading.
A hint
Dividing by zero is a different bug from dividing by text.
These tasks are for you to try on your own machine. Nothing is checked or saved.
What this does not show
No AI assistant is run, so this does not measure whether a bundle helps; the bug and data are made up, and the shrinker is a simple pass, not full delta debugging.
Up next in AI coding and productivity
More in AI coding and productivity
Related videos
- #171 TDD With an AI Assistant: Red, Green, Refactor (unittest) AI coding and productivity
- #179 Git Merge Conflicts: Check Before You Accept a Fix AI coding and productivity
- #20 AI Coding Assistant Workflow: Copy, Test, Read the Diff AI coding and productivity
- #01 Local AI Agent in Python: No API Key (Ollama) AI agents and MCP
