Repository navigation
feat: migrate parser.rs to PRS-0xx structured error codes — #277 (2/6) - #366
Merged
Merged
Conversation
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
Collaborator
Author
|
Reopening to retrigger CI — rust.yml/rust-clippy.yml never fired on the initial push or an empty retrigger commit. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
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 sitesmigrated. This PR wires up the PRS (parser) category — the largest, at 79
codes — in
src/query/datalog/parser.rs.parser.rs's internalResult<_, String>signatures (118 errorsites across ~30 functions) to
anyhow::Result<_>, per the decisionrecorded in the foundation PR (
parser.rscouldn't usebail_coded!/err_coded!as a drop-in without this — they produceanyhow::Error).PRS-0xxcodes to their call site viabail_coded!/err_coded!, matched by content againstdocs/ERROR_REFERENCE.md.src/db.rs's threeparse_datalog_command()call sites(
Minigraf::execute,WriteTransaction::execute,Minigraf::prepare)drop their
.map_err(|e| anyhow::anyhow!("{}", e))— that stringified anddiscarded any
CodedErrorchain beforeMinigrafError::fromcould recoverit at the API boundary.
docs/ERROR_REFERENCE.md's PRS "Error text" lines now show the real{}-templated form (matching theINT-000convention alreadyestablished) instead of a fully-rendered example value — verified
byte-for-byte against
error.rs'sREGISTRYby the existingregistry_is_a_subset_of_error_reference_docsync test."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-resultsvalidation, a handful of(not-join)/(or)structuralmessages) — these still fall back to
INT-000viaMinigrafError::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() >= 4conditions guarding their call sitesalready 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 testfunctions in
tests/error_codes_prs_test.rs, covering all 77reachable PRS codes end-to-end through
db.execute()anddb.prepare(), asserting both.code()and.category())tests/error_codes_foundation_test.rs's placeholder assertion(
execute_parse_error_returns_coded_error) fromINT-000/Internalto the real
PRS-005/Parserit now producescargo clippy --all-features -- -D warnings— clean (matches.github/workflows/rust-clippy.yml's exact invocation)cargo fmt --check— cleanDoes 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