summaryrefslogtreecommitdiff
path: root/src/xact.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-03-16 04:29:35 -0500
committerJohn Wiegley <johnw@newartisans.com>2012-03-16 04:29:35 -0500
commit2605d8a711348dd677a99749b155ed2d6085cd59 (patch)
treee235defb8f584c74ee9dcdbffc4de2ec33e7fe9d /src/xact.cc
parent7462d09b214f2497d9d41a24f4fa8a4dd1577aba (diff)
downloadfork-ledger-2605d8a711348dd677a99749b155ed2d6085cd59.tar.gz
fork-ledger-2605d8a711348dd677a99749b155ed2d6085cd59.tar.bz2
fork-ledger-2605d8a711348dd677a99749b155ed2d6085cd59.zip
Improved error reporting for bad account names
Fixes #374
Diffstat (limited to 'src/xact.cc')
-rw-r--r--src/xact.cc23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/xact.cc b/src/xact.cc
index 4e8e56fa..f514776f 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -111,6 +111,14 @@ value_t xact_base_t::magnitude() const
return halfbal;
}
+namespace {
+ inline bool account_ends_with_special_char(const string& name) {
+ string::size_type len(name.length());
+ return (std::isdigit(name[len - 1]) || name[len - 1] == ')' ||
+ name[len - 1] == '}' || name[len - 1] == ']');
+ }
+}
+
bool xact_base_t::finalize()
{
// Scan through and compute the total balance for the xact. This is used
@@ -136,8 +144,19 @@ bool xact_base_t::finalize()
p.rounded().reduced() : p.reduced());
}
else if (null_post) {
- throw_(std::logic_error,
- _("Only one posting with null amount allowed per transaction"));
+ bool post_account_bad =
+ account_ends_with_special_char(post->account->fullname());
+ bool null_post_account_bad =
+ account_ends_with_special_char(null_post->account->fullname());
+
+ if (post_account_bad || null_post_account_bad)
+ throw_(std::logic_error,
+ _("Posting with null amount's account may be mispelled:\n \"%1\"")
+ << (post_account_bad ? post->account->fullname() :
+ null_post->account->fullname()));
+ else
+ throw_(std::logic_error,
+ _("Only one posting with null amount allowed per transaction"));
}
else {
null_post = post;