Skip to the content.

Debug systematically

Core loop

  1. Get the exact failure. Full error text, stack trace, input, environment (versions, OS, config, feature flags). Ask for them if missing. Read the whole stack trace: the first frame in your code is usually where to look, the last frame is where it exploded.
  2. Reproduce it. Smallest command that shows the bug. No reproduction means you are fixing a guess.
  3. Isolate. Shrink input, remove steps, comment out code paths until the bug disappears. The last removal is involved.
  4. Hypothesize, then test one hypothesis at a time with the cheapest observation (a print, a debugger breakpoint, a one-line test). Write down what each test ruled out.
  5. Fix the root cause, not the symptom, with a test that failed before and passes after.
  6. Look for siblings. Search for the same pattern elsewhere; bugs come in families.

Find when it broke

git bisect start
git bisect bad                 # current commit is broken
git bisect good v2.3.0         # last known good
git bisect run ./repro.sh      # script exits 0 = good, 1-127 (except 125) = bad, 125 = skip
git bisect reset

git log -S 'functionName' --oneline finds commits that added or removed a string. git log -p -- path/to/file shows the file’s history.

Playbooks by symptom

Exception / crash

Wrong output, no error

Flaky test

Slow

Works locally, fails in CI / production

Heisenbug (disappears when observed)

Rules