From 2605d8a711348dd677a99749b155ed2d6085cd59 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 16 Mar 2012 04:29:35 -0500 Subject: Improved error reporting for bad account names Fixes #374 --- src/xact.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/xact.cc') 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; -- cgit v1.2.3