Repository navigation
feat: migrate db.rs to API-0xx and audit remaining call sites to INT-0xx — #277 (6/6) - #368
Merged
Merged
Conversation
…0xx — #277 (6/6) Final sub-PR of the #277 structured error codes umbrella issue. Part 1: migrates src/db.rs's remaining API-layer bail!/anyhow! call sites to their documented API-0xx codes (API-001 write lock poisoned, API-002 unexpected command variant, API-003/004 attribute-keyword/pseudo-attribute at the materialize_transaction/materialize_retraction layer, API-005/006/007 db.prepare() rejecting transact/retract/rule, API-008 function registry lock poisoned, API-009 WAL not initialized), with regression tests asserting the exact code for every reachable one (including two new lock-poisoning tests using catch_unwind to genuinely poison write_lock/ functions rather than just inspecting the code path). Part 2: audits every remaining uncoded bail!/anyhow! call site crate-wide (~250 sites across 18 files) and assigns each a new INT-0xx code (INT-001 through INT-055) with a docs/ERROR_REFERENCE.md entry, using parameterised shared codes for mechanically-repeated call sites (e.g. INT-011 for all ten "unexpected end of <clause>" parser messages, INT-050 for all thirteen lock-poisoned sites across four files, INT-048/INT-049 as broad storage overflow/invariant buckets) rather than one code per line — mirroring the QRY-005/STG-016/WAL-006 pattern already established for wrapping an arbitrary underlying cause. Two regression tests that had locked in INT-000 for the recursion-limit and aggregate-type-mismatch families (out of scope for the QRY PR) were updated to their new INT-020/ INT-041 codes. Upgrades the REGISTRY<->ERROR_REFERENCE.md sync test from subset-checking to full bidirectional equality (registry_matches_error_reference_doc_bidirectionally), now that every documented code has a real call site behind it. Final tally: 186 total ErrorCode variants (122 pre-existing + 9 new API-0xx + 55 new INT-0xx). Release binary: 1068 KiB, well under the 1200 KiB budget. Closes #362 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P7e4uTBWtM8fMZiPZc4bCw
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
CI runs clippy 1.98.0, which flags format!("literal") with no
interpolation as useless_format; the local toolchain here (1.94.0)
doesn't yet catch these. 19 sites in btree.rs/btree_v6.rs — all from
this PR's INT-048/INT-049 migration — wrapped a static message in
format!() with nothing to interpolate. Switched to .to_string() per
clippy's own suggested fix.
Part of #277
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Final sub-PR of the #277 structured error codes umbrella issue. See the design spec (
docs/superpowers/specs/2026-08-25-structured-error-codes-design.md) for background — this closes out both the "API+INT category PR" (step 6 of the migration phasing) and the "Directionality note"'s deferred bidirectional sync-test upgrade.Part 1 —
src/db.rs→API-0xx:API-001write lock poisoned (execute/begin_write/checkpoint)API-002unexpected command variant in write path (structurally unreachable — no test possible, kept for defensive completeness)API-003/API-004attribute-must-be-keyword / cannot-transact-a-pseudo-attribute, mirroringQRY-002/QRY-003at thematerialize_transaction/materialize_retractionlayerAPI-005/API-006/API-007db.prepare()rejectingtransact/retract/ruleAPI-008function registry lock poisoned (register_aggregate/register_predicate)API-009WAL not initialized (also structurally unreachable)Regression tests assert the exact code for every reachable one, including two new tests that genuinely poison
write_lock/functionsviacatch_unwindto exerciseAPI-001/API-008for real.db.rs's "invalid entity"/"invalid value" checks and itsWriteTransaction-already-active reentrancy check have noAPI-0xx(or any) documented counterpart, so they became newINT-001/INT-002/INT-003.Part 2 — crate-wide audit →
INT-0xx: every other uncodedbail!/anyhow!site (~250 of them, across 18 files) got one of 52 new codes (INT-004–INT-055), each with adocs/ERROR_REFERENCE.mdentry. Mechanically-repeated call sites share one parameterised code rather than getting one each — mirroring theQRY-005/STG-016/WAL-006pattern already established in this codebase for "wrap an arbitrary underlying cause" and "one poisoned-lock code per resource" (e.g.INT-011covers all ten "unexpected end of<clause>" parser messages,INT-050covers all thirteen lock-poisoned sites across four files,INT-048/INT-049are broad storage overflow/invariant buckets). The old "Appendix: Internal Errors" bullet list inERROR_REFERENCE.mdis gone, replaced byINT-006's formal entry.Two existing regression tests (
tests/error_codes_qry_test.rs, plus two unit tests insrc/query/datalog/evaluator.rs) had deliberately locked inINT-000for two families out of the QRY PR's scope (recursion/derived-facts/result-limit, and runtime aggregate type mismatch) — updated to assert their newINT-020/INT-041codes.Sync test:
registry_is_a_subset_of_error_reference_doc→registry_matches_error_reference_doc_bidirectionally, now asserting fullREGISTRY == docequality rather than justREGISTRY ⊆ doc, per the design spec's directionality note.Final tally: 186 total
ErrorCodevariants (122 pre-existing + 9 newAPI-0xx+ 55 newINT-0xx). Release binary: 1068 KiB, well under the 1200 KiB CI budget.Test plan
cargo test— full suite green (unit + integration + doctests)cargo clippy --all-features -- -D warnings— cleancargo fmt --check— cleanAPI-0xxcode, including two genuine lock-poisoning tests viacatch_unwindregistry_matches_error_reference_doc_bidirectionallypasses (full bidirectional equality)Per repo convention, per [[feedback_pr_ownership]] I'd normally own this through CI, but the orchestrating session for this #277 cascade is handling CI monitoring, rebase/conflict resolution, and the final merge for the whole cascade — see the issue for context. Not merging; leaving open for review.
Closes #362
🤖 Generated with Claude Code
https://claude.ai/code/session_01P7e4uTBWtM8fMZiPZc4bCw