getTableCount errors are discarded, so a failed query reports as a count of zero #96
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Surfaced during the #71 branch triage. Small, but it is the same failure
shape this repo has spent the day removing from its gate: a value that is
wrong reports as a plausible number rather than as an error.
The code
internal/vaultik/snapshot.go, seven call sites, every one discarding theerror:
getTableCountreturns(int64, error). On error the count is the zerovalue, and these are before/after pairs used to report what an operation
changed. So a failed query does not surface as a failure — it silently
becomes
0, and the delta computed from it is wrong in a directionthat looks like real work happened (or did not).
Why it is worth fixing rather than shrugging at
The #71 triage found this while establishing that
fix/sql-injection-whitelistwould have brokenmain: that branch'sallow-list omits the
snapshotstable, sogetTableCount("snapshots")would have started failing — and because the error is discarded, the
count would have silently become 0 with no error anywhere. A latent
error-swallow turned a would-be loud failure into a silent wrong number.
That is precisely the class of defect that made a "security fix" look
harmless.
Exposure today is nil in the sense that every call site passes a literal
that the sanitizer accepts. The defect is that the code cannot tell you
when that stops being true.
Definition of done
are diagnostic counts, so aborting the operation is probably wrong —
the right shape is likely to surface the failure (log at warn, or
render the count as unknown rather than
0) so a broken query isvisible. Decide deliberately and state the choice; do not simply
propagate the error upward if that changes when the command fails.
0. Whateverrepresentation is chosen —
unknown,-, omitted — a reader must beable to distinguish "the table is empty" from "we could not ask".
--jsonoutput makes the same distinction, per the precedent set in#64, where
remote_presentisnullrather thanfalsewhen theanswer is unknown.
getTableCountto fail and assertthe output does not claim zero.
, _ :=discards ininternal/vaultikhave thesame shape — a discarded error feeding a user-visible number. Fix them
consistently or record why they are fine.
script/cibuildexits 0, verified per #93 (expectedokcount, zero(cached)markers, plausible wall time).