Improve an error message relating to balance assertions

This commit is contained in:
John Wiegley 2014-04-16 15:56:30 -05:00
parent f73ff40a86
commit aa2ff2b5db

View file

@ -1609,22 +1609,25 @@ post_t * instance_t::parse_post(char * line,
"line " << context.linenum << ": " << "post amount = " << amt); "line " << context.linenum << ": " << "post amount = " << amt);
amount_t diff = amt; amount_t diff = amt;
amount_t tot;
switch (account_total.type()) { switch (account_total.type()) {
case value_t::AMOUNT: case value_t::AMOUNT:
diff -= account_total.as_amount(); tot = account_total.as_amount();
break; break;
case value_t::BALANCE: case value_t::BALANCE:
if (optional<amount_t> comm_bal = if (optional<amount_t> comm_bal =
account_total.as_balance().commodity_amount(amt.commodity())) account_total.as_balance().commodity_amount(amt.commodity()))
diff -= *comm_bal; tot = *comm_bal;
break; break;
default: default:
break; break;
} }
diff -= tot;
DEBUG("post.assign", DEBUG("post.assign",
"line " << context.linenum << ": " << "diff = " << diff); "line " << context.linenum << ": " << "diff = " << diff);
DEBUG("textual.parse", "line " << context.linenum << ": " DEBUG("textual.parse", "line " << context.linenum << ": "
@ -1634,7 +1637,9 @@ post_t * instance_t::parse_post(char * line,
if (! post->amount.is_null()) { if (! post->amount.is_null()) {
diff -= post->amount; diff -= post->amount;
if (! no_assertions && ! diff.is_zero()) if (! no_assertions && ! diff.is_zero())
throw_(parse_error, _f("Balance assertion off by %1%") % diff); throw_(parse_error,
_f("Balance assertion off by %1% (expected to see %2%)")
% diff % tot);
} else { } else {
post->amount = diff; post->amount = diff;
DEBUG("textual.parse", "line " << context.linenum << ": " DEBUG("textual.parse", "line " << context.linenum << ": "