File and Lines
internal/agent/error_swallow_check.go lines 69-83 (checkErrorSwallowing)
Problem
The delta detection logic uses a count-based offset (newInstances[oldCount+i]) that assumes new error-swallowing instances always appear AFTER old instances in the position-ordered list. When new code is added at the BEGINNING of a file, the new instance appears at index 0, and the logic reports an OLD instance as "newly introduced" while missing the actual new instance.
Trigger Scenario
Before edit (oldContent) — 2 existing swallows:
func oldFunc1() error {
err := doSomething()
if err != nil {} // OLD instance 1
return nil
}
func oldFunc2() error {
err := doSomething()
if err != nil {} // OLD instance 2
return nil
}
oldCount = 2
After edit (newContent) — new function added at top:
func newFunc() error {
err := doSomething()
if err != nil {} // NEW instance at index 0
return nil
}
func oldFunc1() error { ... if err != nil {} ... } // OLD at index 1
func oldFunc2() error { ... if err != nil {} ... } // OLD at index 2
Delta logic execution:
oldCount = 2, len(newInstances) = 3
newCount = 3 - 2 = 1
- Loop:
i=0, accesses newInstances[0+2] = newInstances[2] = OLD instance at line 22
- Warning issued for OLD instance — NEW instance at index 0 is MISSED
Expected vs Actual Behavior
- Expected: New error-swallowing at the beginning of a file should be detected and flagged.
- Actual: New instance is missed (false negative), old instance is misattributed as "newly introduced".
Root Cause
findErrorSwallows() returns instances ordered by source position (top to bottom). The delta logic assumes indices 0..oldCount-1 = OLD, oldCount..end = NEW. This only works when code is appended to the end. When code is prepended, old instances shift to higher indices and the offset breaks.
Severity
MEDIUM — Only affects delta detection (new files and appends work correctly). Causes both false negatives (missed new bugs) and misattribution (flagging old code as new).
Fix Suggestion
Since error swallowing detection is fast (<1ms), the simplest robust fix is to drop delta optimization entirely and report all instances each time. Alternatively, use position-based matching (store token.Pos for old instances and match against new ones).
File and Lines
internal/agent/error_swallow_check.golines 69-83 (checkErrorSwallowing)Problem
The delta detection logic uses a count-based offset (
newInstances[oldCount+i]) that assumes new error-swallowing instances always appear AFTER old instances in the position-ordered list. When new code is added at the BEGINNING of a file, the new instance appears at index 0, and the logic reports an OLD instance as "newly introduced" while missing the actual new instance.Trigger Scenario
Before edit (oldContent) — 2 existing swallows:
oldCount = 2After edit (newContent) — new function added at top:
Delta logic execution:
oldCount = 2,len(newInstances) = 3newCount = 3 - 2 = 1i=0, accessesnewInstances[0+2]=newInstances[2]= OLD instance at line 22Expected vs Actual Behavior
Root Cause
findErrorSwallows()returns instances ordered by source position (top to bottom). The delta logic assumes indices0..oldCount-1= OLD,oldCount..end= NEW. This only works when code is appended to the end. When code is prepended, old instances shift to higher indices and the offset breaks.Severity
MEDIUM — Only affects delta detection (new files and appends work correctly). Causes both false negatives (missed new bugs) and misattribution (flagging old code as new).
Fix Suggestion
Since error swallowing detection is fast (<1ms), the simplest robust fix is to drop delta optimization entirely and report all instances each time. Alternatively, use position-based matching (store
token.Posfor old instances and match against new ones).