A 31-digit number in a cost spec (`{N USD}`, `{{N USD}}`, either side of
`#`) was dropped with no parse error: the cost became unknown and the
only diagnostic was booking's `interpolation failed`. On a `price` or
`balance` line the directive got a generic `unexpected input` over the
line, and in a balance tolerance, a metadata, `custom` or `pushmeta`
value the number was dropped with no error at all. Each is now reported
at the number (`invalid number in cost (likely exceeds 28-digit Decimal
precision)`, `in amount`, `in metadata value`, ...), as an amount's and
an `@` price's always were (that wording is unchanged). An expression
holding such a number is reported at the number rather than as an
unevaluable expression. beancount 3.2.3 accepts these numbers: P10.
The error oracle's `divide-by-zero` (P9) and `decimal-precision` (P10)
overlays matched these errors by the start of their message. They now
match a typed discriminator, `ParseError::number_error`
(`NumberError::{UnevaluableExpression, BeyondPrecision}`, new), set at
every emitting site, following #3093's `check`. P10 is now claimed, like
P9, only on a line beancount reads and reports nothing on, so an invalid
token after such a number keeps its name.
Cost-spec numbers are checked in the shared cost-spec rule of both tree
walks and the tree builder's recorder; metadata and `pushmeta` values in
the metadata line check; `custom` values in the shared value walk.
Loader cache v86, WASM cache v170: a file that loaded clean (a cost or
metadata number beyond precision) now has a parse error.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
What
A number with more significant digits than
rust_decimalholds (P10) is now a parse error at the number in every context, and the error oracle tells P9/P10 errors apart by a typed discriminator instead of their message prefix.Correctness bug fixed first: a 31-digit number in a cost spec was dropped with no parse error, the cost became unknown, and the only diagnostic was a misleading
BOOK interpolation failed.Before / after (
N=1234567890123456789012345678901, 31 digits)Assets:A 1 HOOL {N USD}(and{{N USD}},{N # 1 USD},{1 # N USD},{N USD, 2024-01-01})BOOK interpolation failedP0012 invalid number in cost (likely exceeds 28-digit Decimal precision)atN(the BOOK follow-on remains, as for an amount){1+N USD}1 USDNprice HOOL N USD,price HOOL -N USDP0012 unexpected inputover the whole linein amount) atNprice HOOL 1+N USDmalformed amount: expected one number…Nbalance Assets:A N USDBalance failed(load-time)P0012 unexpected inputover the lineNbalance Assets:A 1 ~ N USDN(balance kept, no tolerance)kk: N,kk: N USD, posting metadataNone/ the currencyinvalid number in metadata value …atNcustom "b" N USDinvalid number in custom value …pushmeta kk: Ninvalid number in pushmeta value …Assets:A N USD,@ N USD,@@ N USDin amount)Assets:A 1+N USD,kk: 1+Ninvalid arithmetic expression …N(the number is the reason)Assets:A N USD $Invalid token: '$'unexpected input: invalid token '$'(beancount's error on that line)Every one of these was checked with
bean-check(beancount 3.2.3); none is a beancount syntax error, so each P10 error is rledger's own (documented deviation P10).How
ParseError::number_error: Option<NumberError>(new,NumberError::{UnevaluableExpression, BeyondPrecision}), a sibling of refactor(parser): classify builder checks by EntryCheck, drop RLEDGER_ERROR_ORACLE #3093'scheckfield (checkis classifiedErrorClass::Otherby the reconciler, which these must not be). Set at every emitting site: the amount path's two errors,unevaluable_value_error(all its callers), and the newbeyond_precision_error.divide-by-zeroanddecimal-precisionoverlays match onnumber_errorinstead ofstarts_with("invalid arithmetic expression")/starts_with("invalid number in amount (likely exceeds").decimal-precisionnow claims an error only on a line beancount reads and reports nothing on (asdivide-by-zeroalready did), so on a line beancount reports, the reconciler pairs beancount's error with rledger's diagnostic on its token (the$row above). Without this, 4 fuzz inputs lost the name of an invalid token to the P10 message.number_beyond_precision) in the green walk'scost_spec_errors, the redextract_unclosed_cost_brace_errors, and the tree builder's recorder (LineChecks::cost_spec, so the walk-free shortcut cannot skip it; debug builds assert agreement). Metadata/pushmeta:meta_number_beyond_precisioninMetaCheck::line,directive_header_checkand the recorder'smeta.custom:values_beyond_precision, shared by the green and red value walks.price/balance:directive_value_beyond_precisionbefore the malformed-value fallback, plus the tolerance check.number_beyond_precisiononly parses a token longer than 28 bytes (shorter ones always fit), so metadata lines pay one length compare.Proof
crates/rustledger-parser/tests/number_beyond_precision.rs: every context above (one error, at the number, exact message and discriminator), the cost staying unknown, 28 digits clean everywhere, P9 discriminator on1/0in amount/metadata/custom/pushmeta, and beancount's error winning on a line it reports.parse_error_lines --jsonl+semantic_snapshot, 45,182 inputs: pinnedfuzz_parse+fuzz_green_eq_redcorpus, compat corpus, every tracked ledger, profiling workloads; release builds oforigin/main1f4b9dc and this branch). 18 inputs differ, all fuzz inputs, all the same change: an expression holding a >28-digit number was reported as P9 (invalid arithmetic expression in metadata value …×15,… in amount …×3) and is now P10 at that number, on the same line, same code, same count. No compat or tracked ledger changes.semantic_snapshotdiffers on exactly those 18 (the error message only).compat-parse-error-parity --check: no regressions, 122,533 / 123,394 matching, identical toorigin/main.compat-semantic-parity --check: no regressions, 9,563 match / 7 mismatch, identical toorigin/main. No manifest re-pin needed.cargo test -p rustledger-parser -p rustledger-loader -p rustledger-lsp -p rustledger-wasm --all-features(debug, so the recorder/walk agreement asserts run): 2,415 passed, 0 failed.cargo test -p rustledger-surface-parity-tests: passed.cargo clippy --all-features --all-targets -- -D warningson parser/loader/lsp/wasm/rledger: clean.CACHE_VERSION85→86 (with bothFIXTURE_VERSIONs), WASM 169→170 (and its loader pin): a file that loaded clean (a cost or metadata number beyond precision) now has a parse error.compatibility.mdP9 and P10 updated. CHANGELOG: Fixed.Merge note
This and the other parser PRs of this batch (#3162 line-start
\r, #3168 BOM on line 1, #3169 leading-gap indented comment, #3170 oracle line index) are independent branches offmain; each bumps the cache versions to 86/170, so whichever lands second needs a trivial rebase ofcache.rs(bump again).🤖 Generated with Claude Code