learning-it by example

#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.

1. When you ask an AI assistant to help with a crash, what does the video say to give it instead of only the last line of the error?
2. In the video's Python shrinker run on eight made-up orders, the shrink step cut the input down. How far did it get, and how many test runs did it take?
3. Why must a shrunk input still fail with the same error as the real program?
4. How does the shrink function decide whether to keep a cut, such as dropping a row or a field?
5. What does the video say its demonstration does not show about AI assistants?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. 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.

  2. 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.

  3. 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.

  4. 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

All AI coding and productivity videos

Related videos