8000 feat: migrate storage call sites to STG-0xx error codes — #277 (3/6) by adityamukho · Pull Request #365 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

feat: migrate storage call sites to STG-0xx error codes — #277 (3/6) - #365

Merged
adityamukho merged 4 commits into
mainfrom
error-codes-277-stg
Aug 25, 2026
Merged

adityamukho merged 4 commits into
mainfrom
error-codes-277-stg

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Summary

Part of the #277 structured runtime error codes rollout — this is the STG sub-issue (#359), step 3 of 6.

  • Migrates every bail!/anyhow! call site in src/storage/{mod,persistent_facts,btree,btree_v6,packed_pages}.rs and src/storage/backend/file.rs that matches one of the 27 documented STG-0xx codes in docs/ERROR_REFERENCE.md to bail_coded!/err_coded!.
  • Adds all 27 ErrorCode::StgNNN variants and REGISTRY entries to src/error.rs.
  • Rewrites 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-match REGISTRY — verified by the existing registry_is_a_subset_of_error_reference_doc sync test.
  • Fixes FileBackend::open_with so a more specific header-parse failure (e.g. a bad magic number, now STG-002) is no longer swallowed into the generic STG-010 — it propagates an existing CodedError in the chain as-is, only falling back to STG-010 for a genuinely uncoded failure. Verified end-to-end: opening a garbage .graph file now correctly returns STG-002, not STG-010.
  • Two 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.md at repo root) updated under Unreleased.

Codes migrated / not covered by a dedicated test

All 27 STG-0xx codes 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:

  • STG-011: guarded by a debug_assert_eq! that always fires first in a debug/test build (no argument combination with empty child_ids satisfies it), so the bail_coded! site is release-build-only and unreachable under cargo test.
  • STG-017–024 (8 codes): arithmetic-overflow guards requiring near-u64::MAX page counts to trigger — the doc itself calls these "should not occur under normal operation" / "practically unreachable".
  • STG-027: requires a filesystem that refuses locking outright; the existing code comment in file.rs already 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 — clean
  • New integration tests in tests/error_codes_storage_test.rs assert specific STG-NNN codes come back through the public Minigraf::open() API for corrupt .graph files
  • New unit tests inside the storage modules cover codes only reachable below the crate-private storage module 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

adityamukho and others added 2 commits August 25, 2026 18:51
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
@codecov
codecov Bot commented Aug 25, 2026 •
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.11111% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/error.rs 0.00% 5 Missing ⚠️
src/storage/persistent_facts.rs 85.18% 4 Missing ⚠️
src/storage/backend/file.rs 57.14% 3 Missing ⚠️
src/storage/btree_v6.rs 0.00% 1 Missing ⚠️

📢 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
@adityamukho
adityamukho merged commit 8c42609 into main Aug 25, 2026
16 checks passed
@adityamukho
adityamukho deleted the error-codes-277-stg branch August 25, 2026 19:55
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 storage call sites to STG-0xx codes

1 participant

0