[core-be-agent] fix(delegations): add rows.Err() check after ledger and activity_logs iteration
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:
parent
d7f0c1272b
commit
988cf404d4
@ -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{}{}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user