Repository navigation
fix(state): propagate tx indexer database errors - #1357
Conversation
The tx KV indexer returned database read failures by panicking inside Get, match, and matchRange. These run synchronously on the tx-search RPC path, so a transient storage error terminated the query path instead of surfacing as a query error. Convert the storage-error panics to error returns, matching the block KV indexer sibling: iterator-creation failures and post-iteration Iterator.Error() failures in match/matchRange now return through Search, and Get returns a wrapped error. The match/matchRange signatures gain an error return and Search propagates it. Programming-invariant guards (the unhandled-operator default and the key-encoding marshalling helpers) keep their panics. Also converts the match function's untagged switch to a tagged switch on c.Op (staticcheck QF1002). Adds table-driven tests covering creation-time and post-iteration storage errors for Get, match (=, EXISTS, CONTAINS), and matchRange. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
✅ Review complete (commit f7cd35d) |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
PR #1357 is a clean, well-scoped defensive fix that converts panics from transient DB read failures into propagated errors on the tx-search RPC path in internal/state/indexer/tx/kv/kv.go. The encoding helpers that retain panics (primaryKey/secondaryKey/prefix*) are correctly left alone since they encode literals that cannot fail in practice. Test coverage is solid: the new errorDB/errorIterator harness exercises all three match operators (TEq/TExists/TContains), matchRange, both iterator-open and post-iteration Error() failure modes, and the hash-lookup Get path. No consensus, signing, BLS, quorum, or trust-boundary defects were introduced or exposed.
💬 1 nitpick(s)
Four bare `it.Error()` returns in the tx/kv indexer (TEq, TExists, TContains, and matchRange loops) were emitting raw errors with no breadcrumb, while the corresponding iterator-open failures had proper `fmt.Errorf` context. Wrap all four with "prefix iterator failed during scan: %w" so callers get consistent, actionable error messages. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
PR #1357 is a narrow, well-scoped defensive fix that converts panics from transient DB read failures in the tx-search RPC path (internal/state/indexer/tx/kv/kv.go) into propagated errors. Head f7cd35d resolves the only prior nit by wrapping all four post-iteration it.Error() returns with prefix iterator failed during scan: %w. Verified directly against the file: lines 311, 335, 366, 470 are wrapped; remaining panics are encode-cannot-fail assertions. No in-scope findings from either agent.
There was a problem hiding this comment.
Pull request overview
This PR fixes the synchronous tx-search RPC path to gracefully handle transient KV indexer storage failures by returning errors instead of panicking, preventing DB read/iteration errors from crashing the query path.
Changes:
- Updated
TxIndex.Getto return wrapped DB read errors rather than panicking. - Refactored
matchandmatchRangeto return(map[string][]byte, error)and propagate iterator open/scan errors up throughSearch. - Added focused regression tests to ensure
Get/Searchnever panic and surface injected store errors.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/state/indexer/tx/kv/kv.go | Propagates KV store read/iterator errors through Get/match/matchRange/Search instead of panicking. |
| internal/state/indexer/tx/kv/kv_errors_test.go | Adds tests that inject DB failures (Get, iterator open, iterator Error) and assert errors are returned without panics. |
Summary
On the synchronous tx-search RPC path, the tx KV indexer panicked on DB read errors instead of returning them — a transient store error would crash the query path.
Changes
internal/state/indexer/tx/kv/kv.go,Get,match, andmatchRangenow propagate DB read/iteration errors as returnederrors instead ofpanic, so a transient store failure fails the tx-search query gracefully. (Key-encoding helpers keep their encode-cannot-fail panics; those are not on the DB-read path.)🤖 Generated with Claude Code