8000 feat: migrate db.rs to API-0xx and audit remaining call sites to INT-0xx — #277 (6/6) by adityamukho · Pull Request #368 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

feat: migrate db.rs to API-0xx and audit remaining call sites to INT-0xx — #277 (6/6) - #368

Merged
adityamukho merged 3 commits into
mainfrom
error-codes-277-api-int
Aug 26, 2026
Merged

adityamukho merged 3 commits into
mainfrom
error-codes-277-api-int

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

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-001 write lock poisoned (execute/begin_write/checkpoint)
  • API-002 unexpected command variant in write path (structurally unreachable — no test possible, kept for defensive completeness)
  • API-003/API-004 attribute-must-be-keyword / cannot-transact-a-pseudo-attribute, mirroring QRY-002/QRY-003 at the materialize_transaction/materialize_retraction layer
  • API-005/API-006/API-007 db.prepare() rejecting transact/retract/rule
  • API-008 function registry lock poisoned (register_aggregate/register_predicate)
  • API-009 WAL not initialized (also structurally unreachable)

Regression tests assert the exact code for every reachable one, including two new tests that genuinely poison write_lock/functions via catch_unwind to exercise API-001/API-008 for real. db.rs's "invalid entity"/"invalid value" checks and its WriteTransaction-already-active reentrancy check have no API-0xx (or any) documented counterpart, so they became new INT-001/INT-002/INT-003.

Part 2 — crate-wide audit → INT-0xx: every other uncoded bail!/anyhow! site (~250 of them, across 18 files) got one of 52 new codes (INT-004–INT-055), each with a docs/ERROR_REFERENCE.md entry. Mechanically-repeated call sites share one parameterised code rather than getting one each — mirroring the QRY-005/STG-016/WAL-006 pattern already established in this codebase for "wrap an arbitrary underlying cause" and "one poisoned-lock code per resource" (e.g. INT-011 covers all ten "unexpected end of <clause>" parser messages, INT-050 covers all thirteen lock-poisoned sites across four files, INT-048/INT-049 are broad storage overflow/invariant buckets). The old "Appendix: Internal Errors" bullet list in ERROR_REFERENCE.md is gone, replaced by INT-006's formal entry.

Two existing regression tests (tests/error_codes_qry_test.rs, plus two unit tests in src/query/datalog/evaluator.rs) had deliberately locked in INT-000 for two families out of the QRY PR's scope (recursion/derived-facts/result-limit, and runtime aggregate type mismatch) — updated to assert their new INT-020/INT-041 codes.

Sync test: registry_is_a_subset_of_error_reference_doc → registry_matches_error_reference_doc_bidirectionally, now asserting full REGISTRY == doc equality rather than just REGISTRY ⊆ doc, per the design spec's directionality note.

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 CI budget.

Test plan

  • cargo test — full suite green (unit + integration + doctests)
  • cargo clippy --all-features -- -D warnings — clean
  • cargo fmt --check — clean
  • New regression tests for every reachable API-0xx code, including two genuine lock-poisoning tests via catch_unwind
  • registry_matches_error_reference_doc_bidirectionally passes (full bidirectional equality)
  • Release binary size checked locally: 1068 KiB / 1200 KiB budget

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

…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
codecov Bot commented Aug 26, 2026 •
Copy link
Copy Markdown

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
@adityamukho
adityamukho merged commit e913c10 into main Aug 26, 2026
16 checks passed
@adityamukho
adityamukho deleted the error-codes-277-api-int branch August 26, 2026 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error codes: migrate db.rs API-layer call sites to API-0xx, audit remaining sites to INT-0xx

1 participant

0