Visitar URL original
feat(cli): rledger explain — describe validation error codes by robcohen · Pull Request #1675 · rustledger/rustledger · GitHub
Skip to content

feat(cli): rledger explain — describe validation error codes - #1675

Merged
robcohen merged 1 commit into
mainfrom
feat/explain-cmd
Jul 1, 2026
Merged

robcohen merged 1 commit into
mainfrom
feat/explain-cmd

Conversation

@robcohen

@robcohen robcohen commented Jul 1, 2026

Copy link
Copy Markdown
Member

Implements improvement idea #6 — rustc --explain for rledger's E-codes.

$ rledger explain E2001
E2001: Balance assertion failed
severity: Error

A balance assertion does not match the computed balance of the account
(including its sub-accounts) at that date. ... Fix: ...

$ rledger explain            # lists all 26 codes with severities
$ rledger explain 2001       # bare digits + lowercase accepted

Design notes

  • Explanations are code constants on ErrorCode (title()/explanation() via exhaustive match) — adding a variant forces adding its explanation at compile time. New ErrorCode::from_code.
  • Deliberately not include_str! from spec/core/validation.md: published crates don't package spec/, and the Nix flake's crane source filter strips it (the v0.17.x channel-test lesson). The existing error_codes_documented_in_spec test still guards code↔spec drift; explanations were sourced from the spec's per-code Condition/Severity sections.
  • Unknown codes exit non-zero with a pointer to the listing.

Verification

366 CLI + 94 validate tests pass (4 new: spelling roundtrip, full listing, unknown-code exit, every-code-has-substantive-explanation); smoke-tested explain E2001 / bare / E9999; clippy -D warnings + fmt clean.

🤖 Generated with Claude Code

…-explain style

rledger explain E2001 prints the code's title, severity, and a hand-written
explanation (meaning, common cause, fix); bare rledger explain lists all 26
codes with severities; accepts E2001/e2001/2001; unknown codes exit non-zero
with a pointer to the listing.

The text lives on ErrorCode itself (title/explanation via exhaustive match, so
adding a variant forces adding its explanation), plus ErrorCode::from_code.
Deliberately NOT include_str! from spec/core/validation.md: published crates
don't package spec/ and the Nix flake's source filter strips it (the v0.17.x
channel lesson); the existing error_codes_documented_in_spec test still guards
code<->spec drift.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 1, 2026 21:07
@robcohen
robcohen requested a review from a team as a code owner July 1, 2026 21:07
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
crates/rustledger/src/cmd/explain.rs 87.69% 8 Missing ⚠️
crates/rustledger/src/bin/rledger.rs 0.00% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 32.8ms ± 0.6ms 23.8 MB
beancount 911.9ms ± 4.5ms 50.5 MB
Comparison 27.8x faster 2.1x less

vs main branch (2026-07-01)

Metric main this PR Change
Time 36.5ms 32.8ms -10.1% 🟢
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new rledger explain CLI subcommand that mirrors rustc --explain for rustledger’s validation error codes, with explanations stored as compile-time constants on rustledger_validate::ErrorCode to keep the binary self-contained and force completeness via exhaustive matches.

Changes:

  • Adds rledger explain [CODE] to print a code’s title/severity/explanation, and rledger explain to list all codes.
  • Extends rustledger_validate::ErrorCode with from_code(), title(), and explanation() to back the CLI and guarantee per-variant documentation at compile time.
  • Adds focused unit tests for parsing, listing, unknown-code behavior, and explanation presence.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
crates/rustledger/src/cmd/mod.rs Registers the new explain command module.
crates/rustledger/src/cmd/explain.rs Implements the rledger explain command and unit tests.
crates/rustledger/src/bin/rledger.rs Wires the new Explain subcommand into the CLI dispatch.
crates/rustledger-validate/src/error.rs Adds code→variant parsing plus per-code titles and long-form explanations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/rustledger/src/cmd/explain.rs Resolved
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 792
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@robcohen
robcohen merged commit b67516b into main Jul 1, 2026
45 checks passed
@robcohen
robcohen deleted the feat/explain-cmd branch July 1, 2026 21:37
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.

2 participants