Debug like a detective.
Eight real bugs are hiding in Crumbs, a tiny bakery app. Solve each one with a technique you will use for the rest of your career: tracebacks, failing tests, logging, the debugger, bisection, profiling and plain honest assumptions. Clue keeps score.
Evidence #1
KeyError: 'croissant 'Eight open cases.
Each case is a real bug you can run. Every symptom below is real output. Read the evidence, find the culprit, fix the code, and let the checker close the case.
- Case 01Read the tracebackThe missing croissant
KeyError: 'croissant ' - Case 02Reproduce it firstThe customer who was paid to eat
680 cents with TENOFF: pay -320 cents - Case 03Print, then logThe points that keep growing
receipt 3: 3 lines, 324 points - Case 04breakpoint() and pdbThe first page of reviews
page 1: review 11 ... 10 reviews - Case 05Divide and conquerOne bad row in two thousand
ValueError: invalid literal for int() with base 10: 'l2' - Case 06HeisenbugsThe croissant that followed someone home
customer B: ['croissant', 'baguette'] - Case 07Profile, don't guessThe slow regulars report
2199 regulars in 4.64 s - Case 08Assumptions lieThe missing cent
1000 cents for 3: [333, 333, 333] -> adds up to 999
Run it. Fix it. Close it.
- 1
detective run 2watch the bug happen - 2
your editorfind the culprit and fix it - 3
detective check 2real checks say PASS
Case 02 goes further: the checker runs your own test against the original bug, to prove your test would have caught it.
$ uv run python -m detective check 2
PASS a small order with TENOFF costs 0, not less
PASS your test fails on the original bug
PASS your test passes on your fix
_/\_ (o.o) Case 2 closed. Elementary. (Y)
The detective's checklist.
- 1Read the error, last line first
- 2Reproduce it as a failing test
- 3Watch the values: print, then log
- 4Stop and step with breakpoint()
- 5Halve the search space
- 6Suspect shared state, time and order
- 7Measure before you optimise
- 8Write your assumptions down
- 9Explain it out loud
Start in a minute.
You need uv and git. The lab uses the Python standard library only.
git clone https://github.com/jars-demo/debugging-demo.git cd debugging-demo/lab uv sync uv run python -m detective run 1