Fix where it began

Think of it when a fix makes the error go away, but you cannot say why the bad data existed.

In everyday life

Like a water stain on a ceiling. Paint over it and the stain comes back. The fix is the leaking pipe upstairs, which may be two rooms away.

One case

A clinic’s appointment page crashes on appointments that have no patient. An agent adds a guardA check that stops code from running on bad data, such as “if there is no patient, stop”. It hides the problem unless that data is allowed.: if there is no patient, show nothing. The crash stops, but the phone booking screen still saves an appointment with no patient on it, and 40 appointments a week have no one to remind or bill.

The fault began at step 2; the guard changed step 4
The case, cell by cell1 cell = 1 step
Should be: patient on the appointment
yesyesyesyesyes
Phone booking, before the guard
yesnonenonecrashnone
Phone booking, after the guard
yesnonenonehiddennone
Step where it began
2
Step the guard changed
4
The guard turned a crash into a blank page. The appointment still had no patient.

Every case

A bug travels. Bad data is made in one place, passes quietly through several others, and breaks where something finally reads it. The crash marks the end of the trail, not the start. A fix at the crash hides the evidence and lets the same bad data break somewhere else. Ask “why?” at each step until the answer is a wrong decision in the code, not a result of an earlier one. A guard is right only when the state it handles is allowed: a logged-out visitor with no name is normal, an appointment with no patient is not.

The word

Engineers call this

root causeThe first place where things went wrong, not the place where the problem became visible. A fix there removes the bug; a fix at the symptom only hides it.

Follow the bad data back to where it was made, and fix it there. Add a guard only when the state it handles is allowed.

Where this idea leads

Skills that encode it

  • principle-fix-root-causes pstackAsk whether the state is legitimate. If it should never exist, a guard where it broke hides the bug: find what produced it.
  • principle-attack-the-premise pstackWhen two fixes that share one premise fail, write the premise down and test it before a third fix.
  • diagnosing-bugs Matt PocockReproduce and minimise first, then test ranked hypotheses one variable at a time, and name the real cause in the commit.