Skip to content

feat: migrate parser.rs to PRS-0xx structured error codes — #277 (2/6) - #366

Merged
adityamukho merged 3 commits into
mainfrom
error-codes-277-prs
Aug 25, 2026
Merged

adityamukho merged 3 commits into
mainfrom
error-codes-277-prs

Conversation

@adityamukho

Copy link
Copy Markdown
Collaborator

Summary

Step 2 of the 6-PR #277 rollout (structured runtime error codes). The
foundation PR (#357) built the machinery (MinigrafError, ErrorCategory,
ErrorCode, REGISTRY, bail_coded!/err_coded!) with zero call sites
migrated. This PR wires up the PRS (parser) category — the largest, at 79
codes — in src/query/datalog/parser.rs.

  • Converts parser.rs's internal Result<_, String> signatures (118 error
    sites across ~30 functions) to anyhow::Result<_>, per the decision
    recorded in the foundation PR (parser.rs couldn't use
    bail_coded!/err_coded! as a drop-in without this — they produce
    anyhow::Error).
  • Wires all 79 documented PRS-0xx codes to their call site via
    bail_coded!/err_coded!, matched by content against
    docs/ERROR_REFERENCE.md.
  • src/db.rs's three parse_datalog_command() call sites
    (Minigraf::execute, WriteTransaction::execute, Minigraf::prepare)
    drop their .map_err(|e| anyhow::anyhow!("{}", e)) — that stringified and
    discarded any CodedError chain before MinigrafError::from could recover
    it at the API boundary.
  • docs/ERROR_REFERENCE.md's PRS "Error text" lines now show the real
    {}-templated form (matching the INT-000 convention already
    established) instead of a fully-rendered example value — verified
    byte-for-byte against error.rs's REGISTRY by the existing
    registry_is_a_subset_of_error_reference_doc sync test.
  • Two static message strings changed wording to match their documented
    "Error text" verbatim (a pre-existing drift): "Retract argument must be a vector" → "...must be a vector of facts" (PRS-044).

Not in scope / left uncoded: ~40 parser error sites have no documented
PRS code (defensive/unreachable internal errors, :max-derived-facts/
:max-results validation, a handful of (not-join)/(or) structural
messages) — these still fall back to INT-000 via MinigrafError::from,
unchanged from the foundation PR's behavior. Two documented codes are wired
up but structurally unreachable through the public API: PRS-028 ("window
expression cannot be empty") and PRS-049 ("unexpected end of fact
vector") — the has_over/len() >= 4 conditions guarding their call sites
already rule out the case they check for. Pre-existing parser logic, not
introduced by this change.

Test plan

  • cargo test — 1097 passed, 0 failed (was 1081 on main; +16 new test
    functions in tests/error_codes_prs_test.rs, covering all 77
    reachable PRS codes end-to-end through db.execute() and
    db.prepare(), asserting both .code() and .category())
  • Updated tests/error_codes_foundation_test.rs's placeholder assertion
    (execute_parse_error_returns_coded_error) from INT-000/Internal
    to the real PRS-005/Parser it now produces
  • cargo clippy --all-features -- -D warnings — clean (matches
    .github/workflows/rust-clippy.yml's exact invocation)
  • cargo fmt --check — clean
  • Pre-push hook (fmt + clippy + test) passed

Does not close #277 — the umbrella issue for all 6 PRs stays open until
QRY, STG, WAL, and API land too.

Closes #358

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

https://claude.ai/code/session_01P7e4uTBWtM8fMZiPZc4bCw

adityamukho and others added 2 commits August 25, 2026 18:53
Wires up all 79 documented PRS-0xx codes (docs/ERROR_REFERENCE.md) in
src/query/datalog/parser.rs via bail_coded!/err_coded!, replacing the
generic INT-000 fallback the #277 foundation PR (#357) left in place
for every category.

parser.rs's internal Result<_, String> signatures (118 error sites)
convert to anyhow::Result<_> so bail_coded!/err_coded! can be used
directly, per the decision recorded in the foundation PR. db.rs's
three parse_datalog_command() call sites (Minigraf::execute,
WriteTransaction::execute, Minigraf::prepare) drop their
.map_err(|e| anyhow::anyhow!("{}", e)) — that stringified and
discarded any CodedError chain before it could reach
MinigrafError::from at the API boundary.

docs/ERROR_REFERENCE.md's PRS "Error text" lines are updated to show
the real {}-templated form (matching the INT-000 convention already
established) instead of a fully-rendered example value, verified
byte-for-byte against error.rs's REGISTRY by the existing
registry_is_a_subset_of_error_reference_doc sync test.

Two documented codes are wired up but structurally unreachable
through the public API: PRS-028 ("window expression cannot be
empty") and PRS-049 ("unexpected end of fact vector") sit behind
conditions their call sites' own guards already rule out. Pre-existing
parser logic, not introduced by this change.

Adds tests/error_codes_prs_test.rs: 16 test functions covering all 77
reachable PRS codes end-to-end through db.execute() and db.prepare(),
asserting both .code() and .category(). Updates the foundation PR's
placeholder assertion (execute_parse_error_returns_coded_error) from
INT-000/Internal to the real PRS-005/Parser it now produces.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P7e4uTBWtM8fMZiPZc4bCw
@adityamukho

Copy link
Copy Markdown
Collaborator Author

Reopening to retrigger CI — rust.yml/rust-clippy.yml never fired on the initial push or an empty retrigger commit.

@adityamukho adityamukho reopened this Aug 25, 2026
@adityamukho
adityamukho merged commit c75b47f into main Aug 25, 2026
16 checks passed
@adityamukho
adityamukho deleted the error-codes-277-prs branch August 25, 2026 20:07
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.71014% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/query/datalog/parser.rs 79.25% 28 Missing ⚠️

📢 Thoughts on this report? Let us know!

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 parser.rs to PRS-0xx codes post-1.0: add structured error codes to runtime output

1 participant