Repository navigation
feat: migrate storage call sites to STG-0xx error codes — #277 (3/6) - #365
Merged
Merged
Conversation
Part of #359 (STG sub-issue of the #277 structured error codes rollout). Migrates bail!/anyhow! call sites in src/storage/{mod,persistent_facts, btree,btree_v6,packed_pages}.rs and src/storage/backend/file.rs to bail_coded!/err_coded! with their real STG-0xx codes, matched against the 27 documented codes in docs/ERROR_REFERENCE.md. - All 27 ErrorCode::StgNNN variants + REGISTRY entries added to src/error.rs. - docs/ERROR_REFERENCE.md's STG section "Error text" lines rewritten from one-off example values to canonical {}-placeholder templates so they byte-match REGISTRY (verified by the existing sync test). - FileBackend::open_with no longer collapses a more specific header-parse failure (e.g. bad magic number) into the generic STG-010: it now propagates an existing CodedError in the chain as-is, falling back to STG-010 only for a genuinely uncoded failure. - Two bail! sites with no matching documented STG code ("Header checksum mismatch", into_backend's multiple-owners precondition) deliberately left uncoded (INT-000) rather than assigned an undocumented code. - Regression tests: 6 integration tests against the public Minigraf::open() API (tests/error_codes_storage_test.rs) plus unit tests inside the storage modules for codes only reachable below the (crate-private) storage module boundary. Not covered by a dedicated test: STG-011 (guarded by a debug_assert! that always fires first under `cargo test`), the 8 arithmetic-overflow guards STG-017–024, and STG-027 (needs an unlockable filesystem no CI runner provides) — all three categories are documented as "should not occur under normal operation" and are covered by the registry↔doc sync test. toward #277 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P7e4uTBWtM8fMZiPZc4bCw
# Conflicts: # CHANGELOG.md # src/error.rs
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
- Drop derive(Debug) on ErrorCode: with the registry growing to 130 variants across #277's six category PRs, the generated per-variant match arm is pure binary-size cost with no runtime use — nothing formats an ErrorCode with {:?}. - Hand-write CodedError's Debug impl instead of deriving it, reusing the already-formatted message and the stable code string rather than requiring ErrorCode: Debug. - Mark CodedError::new #[cold]/#[inline(never)]: error construction is the cold path at every bail_coded!/err_coded! call site (currently ~50, eventually ~250+), so keep the registry lookup + format_template call out of line instead of duplicating it inline per call site. Toward the binary-size pressure from #277 (see #367's raise of the CI budget from 1MB to ~1.2MB for the full context). 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
Part of the #277 structured runtime error codes rollout — this is the STG sub-issue (#359), step 3 of 6.
bail!/anyhow!call site insrc/storage/{mod,persistent_facts,btree,btree_v6,packed_pages}.rsandsrc/storage/backend/file.rsthat matches one of the 27 documentedSTG-0xxcodes indocs/ERROR_REFERENCE.mdtobail_coded!/err_coded!.ErrorCode::StgNNNvariants andREGISTRYentries tosrc/error.rs.docs/ERROR_REFERENCE.md's STG section "Error text" lines from one-off example values (e.g.got 12 bytes) to canonical{}-placeholder templates so they byte-matchREGISTRY— verified by the existingregistry_is_a_subset_of_error_reference_docsync test.FileBackend::open_withso a more specific header-parse failure (e.g. a bad magic number, nowSTG-002) is no longer swallowed into the genericSTG-010— it propagates an existingCodedErrorin the chain as-is, only falling back toSTG-010for a genuinely uncoded failure. Verified end-to-end: opening a garbage.graphfile now correctly returnsSTG-002, notSTG-010.bail!sites with no matching documented STG code ("Header checksum mismatch",into_backend's multiple-owners precondition) were deliberately left uncoded (INT-000) rather than assigned an undocumented code — left for the final API+INT audit PR (step 6).docs/CHANGELOG.md(CHANGELOG.mdat repo root) updated under Unreleased.Codes migrated / not covered by a dedicated test
All 27
STG-0xxcodes are wired up at their call sites. Dedicated regression tests cover STG-001–010, 012–016, 025, 026 (19 codes). Not covered by a dedicated test, with reasons:debug_assert_eq!that always fires first in a debug/test build (no argument combination with emptychild_idssatisfies it), so thebail_coded!site is release-build-only and unreachable undercargo test.u64::MAXpage counts to trigger — the doc itself calls these "should not occur under normal operation" / "practically unreachable".file.rsalready notes "no CI runner can be relied on to provide a mount whose locks fail".All three categories are still checked by the registry↔doc sync test (byte-exact template match) and by code review.
Test plan
cargo test— full suite green (731 lib tests + all integration/doc tests, up from 721 baseline)cargo clippy --all-features -- -D warnings— clean (matches.github/workflows/rust-clippy.yml's exact invocation)cargo fmt -- --check— cleantests/error_codes_storage_test.rsassert specificSTG-NNNcodes come back through the publicMinigraf::open()API for corrupt.graphfilesstoragemodule boundary (poisoned mutex, corrupted B+tree pages, corrupted packed-page records, etc.)toward #277 — does not close the umbrella issue. Closes #359.
🤖 Generated with Claude Code
https://claude.ai/code/session_01P7e4uTBWtM8fMZiPZc4bCw