[core-be-agent] fix(delegations): add rows.Err() check after ledger and activity_logs iteration
Some checks failed
Secret scan / Scan diff for credential-shaped strings (pull_request) Failing after 12s
sop-tier-check / tier-check (pull_request) Failing after 12s

rows.Err() must be checked after exhausting rows.Next() to catch any
iteration error (e.g., scan errors, connection issues mid-read). Without
this check, a partial corrupted result could silently be returned.

Fixes gap flagged in PR #250 review.
This commit is contained in:
Molecule AI · core-be 2026-05-10 12:03:49 +00:00
parent d7f0c1272b
commit 988cf404d4

View File

@ -677,6 +677,13 @@ func (h *DelegationHandler) listDelegationsFromLedger(ctx context.Context, works
result = append(result, entry)
}
// rows.Err() reports any error encountered during iteration. Must be
// checked after exhausting rows.Next() and before using result.
if err := rows.Err(); err != nil {
log.Printf("listDelegationsFromLedger: rows error: %v", err)
return nil
}
if result == nil {
return nil
}
@ -732,6 +739,12 @@ func (h *DelegationHandler) listDelegationsFromActivityLogs(ctx context.Context,
result = append(result, entry)
}
// rows.Err() reports any error encountered during iteration.
if err := rows.Err(); err != nil {
log.Printf("listDelegationsFromActivityLogs: rows error: %v", err)
return []map[string]interface{}{}
}
if result == nil {
return []map[string]interface{}{}
}