8000 feat: migrate parser.rs to PRS-0xx structured error codes — #277 (2/6) by adityamukho · Pull Request #366 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
string-matches error output is affected, including the interactive REPL's
printed error messages and all 7 language-binding repos (Python, Node,
WASM, Java, Android, Swift, C).
- **`src/query/datalog/parser.rs` now carries real `PRS-0xx` codes instead of
falling back to `INT-000`** (#358, #277 2/6). All 79 documented `PRS-0xx`
codes are wired up via `bail_coded!`/`err_coded!` at every parser call site
that maps onto one; a parse error's `.code()` is now e.g. `"PRS-005"`
("Unclosed list") instead of the generic `"INT-000"`, and its
`Display`/`to_string()` prefix changes to match. `parser.rs`'s internal
signatures changed from `Result<_, String>` to `anyhow::Result<_>`
(crate-internal only — the public `db.execute()`/`db.prepare()` surface is
unchanged, still `Result<T, MinigrafError>`). Two documented codes,
PRS-028 ("window expression cannot be empty") and PRS-049 ("unexpected end
of fact vector"), are wired up but unreachable through the public API — the
`has_over`/`len() >= 4` conditions that guard their call sites already
guarantee the "bad" case can't occur, so no input reaches them. This is a
pre-existing property of the parser logic, not something this PR changed.
Two static message strings changed wording to match their
`docs/ERROR_REFERENCE.md` "Error text" verbatim (previously drifted):
`"Retract argument must be a vector"` → `"...must be a vector of facts"`
(PRS-044). Anything that string-matches parser error output — including
the interactive REPL and all 7 language-binding repos — is affected by
both the code prefix and this wording change.
- **Storage/file-format errors now surface their real `STG-0xx` code** (#359,
part of #277's rollout): all 27 documented `STG-0xx` codes are wired up
across `src/storage/{mod,persistent_facts,btree,btree_v6,packed_pages}.rs`
Expand Down
84 changes: 42 additions & 42 deletions docs/ERROR_REFERENCE.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/db.rs < 8000 svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-copy">
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ impl Minigraf {
);
}

let cmd = parse_datalog_command(input).map_err(|e| anyhow::anyhow!("{}", e))?;
let cmd = parse_datalog_command(input)?;

// Determine if this is a read-only command (query only).
// Rule registration is treated as a write because it mutates the shared RuleRegistry.
Expand Down Expand Up @@ -775,7 +775,7 @@ impl Minigraf {
) -> Result<crate::query::datalog::prepared::PreparedQuery> {
use crate::query::datalog::prepared::prepare_query;

let cmd = parse_datalog_command(query_str).map_err(|e| anyhow::anyhow!("{}", e))?;
let cmd = parse_datalog_command(query_str)?;

let query = match cmd {
DatalogCommand::Query(q) => q,
Expand Down Expand Up @@ -1068,7 +1068,7 @@ impl<'a> WriteTransaction<'a> {
}

fn execute_inner(&mut self, input: &str) -> Result<QueryResult> {
let cmd = parse_datalog_command(input).map_err(|e| anyhow::anyhow!("{}", e))?;
let cmd = parse_datalog_command(input)?;

match cmd {
DatalogCommand::Transact(tx) => {
Expand Down
Loading
Loading
0