Patching the symptom instead of the cause
Spot fixes applied where the error surfaces rather than where it originates: a null check at the crash site, a special case for the failing input, a catch around the throwing line. Explain why the error disappears but the cause keeps producing bad results.
Builds on: Agents optimise the signal they can see
The report runs again. Is it fixed?
Your nightly billing report crashed with `AttributeError: 'NoneType' object has no attribute 'email'`. You pasted the stack trace and asked the agent to fix it.
A minute later the agent reports back. It added two lines, the job runs to the end, and the tests are green. Its summary says: *handled the case where the user is missing*.
Is the bug fixed?
Where it surfaced is not where it started
A stack trace shows where bad data was **noticed**, not where it was **made**. 'Error gone' is the proxy signal. The shortest edit that satisfies it sits at the crash site: a null check, a special case for the failing input, or a catch around the throwing line.
The code that produced the bad value still runs. The crash was your only alarm. **Later cost:** wrong results keep flowing, and nothing reports an error.
Tells, and the question that settles it
Tells:
- The change sits on or right next to the line the stack trace names.
- It branches on the exact value that failed (`None`, `""`, one specific input).
- A `try`/`catch` wraps only the throwing call.
- The summary says it *handles* the bad value but never says *why* the value exists.
Then ask: where was this value made, and is it ever allowed? If it is not allowed, fix the producer. If it is allowed, the guard is right, but only once that is stated.
A guard a few lines below the cause
The crash happens on `user.email`, so the agent guarded there. The cause is a few lines up: `load_users(active=True)` leaves out deactivated customers, but their invoices still arrive.
Now `continue` skips those invoices. **Later cost:** the report finishes and under-counts revenue, with no error anywhere.
The fix at the cause: load every user the invoices reference, including inactive ones. If a user is truly missing, fail loudly.
// Python
--- a/billing/report.py
+++ b/billing/report.py
@@ -3,7 +3,9 @@ def build_rows(invoices):
users = {u.id: u for u in
load_users(active=True)}
rows = []
for inv in invoices:
user = users.get(inv.user_id)
+ if user is None:
+ continue
rows.append((user.email, inv.total))
return rows
A catch that hides a broken writer
A page crashes in `JSON.parse` with a `SyntaxError`. The agent wraps the parse in `try`/`catch` and returns `null`, so the cache simply misses.
Tell: the catch wraps only the throwing call, and nothing says why stored data would be unparseable. Look at the writer: `localStorage.setItem(k, String(obj))` stores `"[object Object]"`. **Later cost:** nothing is ever cached, and every page load silently hits the API.
The fix at the cause: write with `JSON.stringify(obj)`, and drop entries already stored in the broken form, for example by changing the cache key. Then the reader needs no catch for this.
Ask where the bad value came from
An error marks where bad data was noticed, not where it was made. Before you accept a guard, catch or special case at the crash site, ask where the value came from and whether it is ever legitimate. If you skip that question, the cause keeps producing wrong results, and now nothing raises an alarm.
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.