Repository navigation
fix(wasm)!: give a validation finding the hint rledger check gives it - #2973
Merged
Merged
Conversation
validateSource and ParsedLedger mapped a ValidationError through their own rule in validation_error_to_wasm: the hint fell back from the finding's hint to its note to its context, and the note stayed out of the message. So a failing balance (E2001) carried the hint "difference: 1, tolerance: 0", which rledger check, the multi-file WASM surfaces and the FFI do not give. The loader's conversion, which check uses, is now public as rustledger_loader::validation_error_to_ledger_error (process's ledger_errors_extend calls it), and validation_error_to_wasm takes the message, code, phase, hint and severity from it, placing the finding by its own single-source rule as before. A finding's hint is its suggested fix only, its note is folded into the message, its context is not reported, and E1005 is phase "parse", as check reports them. rledger check's output does not change. test_validation_findings_match_the_loaders pins validateSource to the loader field by field (message, code, phase, hint, file, line, column, end, severity) on a failing balance and a ledger with several findings, and one finding carrying a note, a context and a hint through both conversions. WASM cache v111 (v110 is held by #2931), since a ParsedLedger archives its findings; the loader cache stays at v73. Closes #2972 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Review of #2973: - test_validation_findings_match_the_loaders gains an invalid-root ledger (E1005), so validateSource is compared with the loader on a parse-phase code, phase included. Forcing phase "validate" in validation_error_to_wasm now fails it. - rustledger-loader tests validation_error_to_ledger_error directly: the note folded into the message, the context dropped, the hint kept, and a parse-phase code given phase "parse". - The CHANGELOG breaking entry names every code whose context was a hint on validateSource: E2001, E2002, E2003, E8001 and E1005. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hints validateSource drops Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 14, 2026
…r it, as beancount does (#2974) * fix(parser): read a mid-line `#!` or `#+` as a `#` and the token after it, as beancount does A `#!` or `#+` that does not start its line was one comment-like token (`Shebang` / `EmacsDirective`) running to the end of the line. beancount skips a `#` line only at column 0 (`^[\*\:\#]/.`); anywhere else it lexes a `#` (HASH), then a `!` (FLAG) or a `+` (PLUS), and the rest of the line as usual. So every invalid token after a mid-line `#!` went unreported (`2024-01-02 * "x" #!cd` is two errors in bean-check 3.2.3, one here), and an indented `#+STARTUP` or `#!` line, under a directive or a posting, was skipped as a comment where beancount reports it. - Lexer: a `Shebang` / `EmacsDirective` token not at column 0 is rewritten to `Hash`, and the lexer resumes right after the `#`, as the mid-line `%` rewrite does. `error_later_in_run` lexes on past a `#` the same way, so a lone capital glued to `#!x` still makes the run one invalid token. - CST recovery: the mid-line SHEBANG / EMACS_DIRECTIVE special cases are gone (the transaction header's `#!` defect, `indented_comment_check`, the two-character defect range), since those tokens now occur at column 0 only. A header defect at a `#` keeps the "only `;` starts a comment in the middle of a line" hint. Parse-error parity (pinned fuzz corpus 9bc79f4): 78,500 of 111,323 inputs match beancount, from 78,478: 71 newly match, 49 regress. 48 of the 49 count each differing line as beancount does when the line stands alone (beancount's recovery after an earlier error line, #2872), and the other is a lone capital glued to tokens that all lex (`X!!#+++02`). `tracked` and `compat` are unchanged. The BOM combination matrix keeps its beancount and main columns; its generated lists are updated with `BOM_MATRIX_UPDATE=1 BOM_MATRIX_RELABEL=1`, the hand-kept worse-than-main list drops 341 lines no longer further from beancount than main and gains 51 that a hidden `#!` / `#+` used to mask, and a line main counted closer only because it did not read past a mid-line `#!` / `#+` is verified as such (`main_read_less`). Caches: loader v74 and WASM v112. A ledger with an indented `#+` line loaded with no error before, so an error-free v73 loader blob of it is stale too. (WASM v111 is held by #2973.) Refs #2928 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): name a mid-line `#!` or `#+` in its line's error Review round 1 of #2974. - Removing `indented_comment_check` lost the message that named an indented `#!` / `#+`: the line's error became the generic `unexpected input` at the indentation. `name_mid_line_hash_comments`, a shared post-pass beside `name_misspelled_booleans`, finds each mid-line marker with the lexer itself (a `#` followed right away by its `!` or `+`, so never one in a string or a comment) and rewrites the line's first error at or before the `#` to point at the two characters and say that only `;` starts a comment that is indented or in the middle of a line. A defect already reported at the `#` (a posting's, a directive header's) is widened to both characters with the same hint. Only messages and spans move, on the same line, so every count stays beancount's. The hint now also reaches a top-level indented line and a directive's metadata, which main read as comments. Pinned by `tests/mid_line_hash_bang.rs` (exact message and span under a posting, at the top level, after a column-0 `#+TITLE` line, in an `open`'s metadata, and on posting and header lines). - The `Shebang` / `EmacsDirective` arms of `invalid_runs` are gone: its text starts with a blank, so a `#!` there is mid-line. The `is_comment_token` rustdoc no longer calls an indented `#+STARTUP` comment trivia. - BOM matrix harness: `hash_bang_cut` finds the markers with the lexer, so it no longer cuts inside a string or a comment, and `main_read_less` also requires the cut to move the line's count; its doc says it accepts a line whatever its cause. The matrix test passes with no list change. - CHANGELOG: the entry names the restored message and the cache bumps. Refs #2928 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): rename a line's error for a mid-line `#!` only where the marker leads the line Review round 2 of #2974. `name_mid_line_hash_comments` renamed the first generic `unexpected input` anywhere on the line before the `#`, so an earlier real error on the line (`$x` in ` Assets:A 1 USD $x #+y`, `open Assets:A ÜÜ #!x`, a stray `\r` before `#!x`, a line led by `$x`, `true`, `k: true` or `é`) was moved onto the marker and its own report vanished, and the error list could leave its start order. Now the line's error is renamed only when the marker leads its line (after its indentation); otherwise only a defect reported at the `#` itself is widened. Only blanks lie between the line start and a leading marker, so the list stays sorted. Tests in `tests/mid_line_hash_bang.rs`: an earlier bad token keeps its own error over its span (posting, `open` header, a line led by `$x`, metadata), a stray `\r` before `#!x` keeps its error, a `#!` inside a string renames nothing, errors stay sorted by start, and the `#+` of `<BOM> #+x` is bytes 5..7. Per-line counts match bean-check 3.2.3 on every repro. Refs #2928 Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 14, 2026
…s an invalid token (#2975) A transaction whose posting holds an invalid token is kept under error recovery (#2932) with what recovery could read of it, so a posting's price or cost after the token is gone (`1 HOOL <BOM>{2 USD}`, `1 HOOL \x11@ 2 USD`, `1 HOOL $x{2 USD}`). The transaction then did not balance, and every surface reported two `E3001` beside the token's parse error, where bean-check 3.2.3 reports the token alone: beancount's grammar never builds such a transaction. The late balance check now asks, only once it has found a residual, whether the transaction holds an invalid token, by the parser's own rule: `rustledger_parser::transaction_holds_invalid_token` parses the transaction's own text (its directive span) and applies `holds_an_invalid_token`, the rule the duplicate-metadata check already skips such a transaction by. The text comes through `SourceLines`, which every surface already hands the validator: `SourceLines::with_text` / `text`, filled by `rustledger_loader::source_lines_overlaid` from the source map and from an editor's buffers (whose text is now kept), and by the new `source_lines_of_text` for an LSP buffer validated outside a ledger. Without the text (dropped, or a synthesized transaction) the residual is reported as before. A ledger that balances never reads its source here. The parse output is unchanged. Pinned by a surface-agreement case (CLI, loader, WASM, FFI, LSP) for `{`, `@`, `@@`, BOM-led, BOM-glued, control character and invalid-run shapes beside a transaction that really does not balance, by `test_transaction_holds_invalid_token_reads_the_parsers_rule`, and by a loader test of the text access. Caches: WASM v113 (its payloads archive validation findings; v111 is held by #2973 and v112 by #2974). Loader v73, unchanged: every affected source has a parse error, and that cache is saved only for an error-free load. Closes #2954 Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
What
WASM's
validateSourceandParsedLedgernow convert a validation finding through the loader's conversion, whichrledger checkuses, instead of a rule of their own.ValidationError->LedgerErrorconversion (inline inledger_errors_extend) is now public asrustledger_loader::validation_error_to_ledger_error.processstill converts every finding through it, sorledger checkoutput does not change.validation_error_to_wasm(crates/rustledger-wasm/src/helpers.rs) takes the message, code, phase, hint and severity from that function. It still places the finding by the single-source rule (file id 0 viaSourceMap::locate, else the date-to-line fallback), so locations do not change.Why
validation_error_to_wasmsethintto the finding'shint, else itsnote, else itscontext, and left the note out of the message. So a failing balance (E2001) carriedhint: "difference: 1, tolerance: 0", whichrledger check, the multi-file WASM surfaces and the FFI do not give. The loader's rule is the canonical one:hintis the suggested fix only;noteis folded into the message (<message>\n note: <note>);contextis not reported.Calling the loader's function means the rule exists in one place only, per the canonical-function discipline in
AGENTS.md. A side effect:E1005is nowphase: "parse"on these surfaces, ascheckreports it.This is a breaking change to WASM output (see the CHANGELOG
### Breakingentry). WASM cache v111, since aParsedLedgerarchives its findings. v110 is held by #2931. The loader cache is unchanged at v73.Drift guard
test_validation_findings_match_the_loaders(inparse_error_mapping_parity,crates/rustledger-wasm/src/helpers.rs):validateSource's findings with the loader'sLedgerErrors (load_with_fs, asrledger checkloads) on every field: message, code, phase, hint, file, line, column, end line, end column and severity. It runs on two ledgers: theE2001ledger from the issue, and one with several findings after a multi-byte character. On the issue's ledger it also asserts the exact loader row (hint: None).E8001's hint needs thedocumentsroots resolved against a directory, and a single source has no directory.Other surfaces with their own ValidationError mapping (out of scope)
validation_error_to_diagnostic,crates/rustledger-lsp/src/handlers/diagnostics.rs): builds its own message. It appends(date), acontext:line and ahint:line, and drops thenote. That is a separate presentation for an editor, not the wirehintfield. Changing it would change LSP output.semantic_validation_errors,crates/rustledger-ffi-component/src/convert.rs): sends the bareerr.message. The note is not folded in, and the WITerrorrecord has nohintfield. A note never reaches the FFI, whilecheckprints it in the message.check_closingbalance at<check_closing>): the loader locates it at<check_closing>:0:0, andvalidateSourcegives no line. This is a location rule, separate from the hint/note/context rule fixed here.E8001hint:run_validationdoes not resolvedocumentsroots, sovalidateSourcenever gives the documents-folder hint thatcheckand the multi-file surfaces give.How to test
By hand: run
validateSourceon the ledger from the issue.E2001now hashint: null, matchingrledger check --format jsonandvalidateMultiFile.Closes #2972
🤖 Generated with Claude Code