BugForge
All lessons
Core · 01/05 8 min

The debugging playbook

A repeatable loop for any failing codebase: reproduce, localise, explain, fix, verify.

Repository-debugging rounds hand you an unfamiliar service, a ticket and a red test suite. You aren't graded on how clever the fix is; you're graded on whether the tests go green without breaking anything else, inside the time box. A system beats intuition.

The loop

  1. Run the tests first. Before reading any source, see what fails. The failing test names are the spec.
  2. Read one failing test end-to-end. What request does it send? What does it expect back: status, body shape, database state?
  3. Trace the path. Follow the request: app.js → middleware → router → controller → service → model. Use the Request flow tab: the station where the actual behaviour diverges from the expected one is where the bug lives.
  4. Form one hypothesis, in a sentence: "the price is a string, so + concatenates". If you can't say it, you don't understand it yet.
  5. Make the smallest fix that addresses the root cause, not the symptom. Don't rewrite the module.
  6. Re-run everything. A fix that turns one test green and another red is not a fix.

Where bugs hide (in rough order of frequency)

Category Typical shape
Async missing await, forEach(async…), error swallowed in a promise
Off-by-one < vs <=, slice(0, n-1), page * limit instead of (page-1) * limit
Types "10" + 5, req.query values are strings, ObjectId vs string compare
Middleware order auth registered after the routes, express.json() missing
Status codes 200 on create (should be 201), 500 on bad input (should be 400)
Mutation sorting/shared arrays in place, default object reused
Boundaries empty list, missing field, duplicate key, expired token

Time management

  • Spend the first 3 minutes just running tests and skimming the file tree.
  • If you've been staring at one file for 10 minutes, step back and re-read the failing assertion.
  • Fix bugs in the order the tests fail: earlier failures often cause later ones.
  • Use console.log liberally; the Logs tab groups them per test.

Interviewers love hearing the hypothesis out loud: "I think X because Y; let me confirm by Z." Practise narrating it here.

Practise it now
Next in Core
HTTP status codes that tests check