refactor(mcp): previews and totals refuse oversized sums instead of panicking
preview_lines_for (balance before + line), the disposal preview's debits, the depreciation run's catch-up difference, the digest's account movement and the payroll remittance total used raw + / - / .sum() on stored or replayed figures; they now go through ledger_core::money's checked helpers and return the tool's string error (TooLargeToCompute). Unchanged for ordinary input. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
afc7c545da
commit
e6104b49d6
4 files changed
+46
-27
No files matched your search
@@ -839,7 +839,15 @@ impl BooksServer {
|
||||
description,
|
||||
period: r.period,
|
||||
amount: money(r.amount),
|
||||
caught_up: money((r.amount - r.scheduled).max(Decimal::ZERO)),
|
||||
caught_up: money(
|
||||
ledger_core::money::sub_exact(
|
||||
r.amount,
|
||||
r.scheduled,
|
||||
"the catch-up depreciation",
|
||||
)
|
||||
.map_err(|e| e.to_string())?
|
||||
.max(Decimal::ZERO),
|
||||
),
|
||||
entry_id,
|
||||
already_posted: r.already_posted,
|
||||
});
|
||||
@@ -916,14 +924,20 @@ impl BooksServer {
|
||||
.map(code_of)
|
||||
.collect::<Result<_, _>>()?;
|
||||
let code_refs: Vec<&str> = codes.iter().map(|s| s.as_str()).collect();
|
||||
let debits = preview.accumulated
|
||||
+ proceeds.amount
|
||||
+ preview.catch_up_depreciation
|
||||
+ if preview.gain_loss < Decimal::ZERO {
|
||||
-preview.gain_loss
|
||||
} else {
|
||||
Decimal::ZERO
|
||||
};
|
||||
let debits = ledger_core::money::sum_exact(
|
||||
[
|
||||
preview.accumulated,
|
||||
proceeds.amount,
|
||||
preview.catch_up_depreciation,
|
||||
if preview.gain_loss < Decimal::ZERO {
|
||||
-preview.gain_loss
|
||||
} else {
|
||||
Decimal::ZERO
|
||||
},
|
||||
],
|
||||
"the disposal's debits",
|
||||
)
|
||||
.map_err(|e| e.to_string())?;
|
||||
let receipt_required = self
|
||||
.settings()
|
||||
.policy
|
||||
|
||||
Reference in new issue
Block a user