From a77d9fc2617c639f146aeb31b5eaeaa30fa96e5d Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 3 Nov 2009 15:34:08 -0500 Subject: Added error message if a predicate query is invalid --- src/precmd.cc | 11 +++++++++-- src/predicate.h | 3 +-- src/report.cc | 10 +++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/precmd.cc b/src/precmd.cc index a08fd2d6..479d7c2d 100644 --- a/src/precmd.cc +++ b/src/precmd.cc @@ -231,6 +231,9 @@ value_t args_command(call_scope_t& args) out << std::endl << std::endl; std::pair info = args_to_predicate(begin, end); + if (! info.first) + throw_(std::runtime_error, + _("Invalid query predicate: %1") << join_args(args)); call_scope_t sub_args(static_cast(args)); sub_args.push_back(string_value(info.first.text())); @@ -242,8 +245,12 @@ value_t args_command(call_scope_t& args) << std::endl << std::endl; call_scope_t disp_sub_args(static_cast(args)); - disp_sub_args.push_back - (string_value(args_to_predicate(info.second).first.text())); + info = args_to_predicate(info.second); + if (! info.first) + throw_(std::runtime_error, + _("Invalid display predicate: %1") << join_args(args)); + + disp_sub_args.push_back(string_value(info.first.text())); parse_command(disp_sub_args); } diff --git a/src/predicate.h b/src/predicate.h index 5e900234..2ac3cc4b 100644 --- a/src/predicate.h +++ b/src/predicate.h @@ -299,8 +299,7 @@ std::pair args_to_predicate(value_t::sequence_t::const_iterator begin, value_t::sequence_t::const_iterator end); -std::pair -args_to_predicate(query_parser_t parser); +std::pair args_to_predicate(query_parser_t parser); } // namespace ledger diff --git a/src/report.cc b/src/report.cc index 60f6955c..fe482a2e 100644 --- a/src/report.cc +++ b/src/report.cc @@ -413,6 +413,9 @@ namespace { args.value().as_sequence().end(); std::pair info = args_to_predicate(begin, end); + if (! info.first) + throw_(std::runtime_error, + _("Invalid query predicate: %1") << join_args(args)); string limit = info.first.text(); if (! limit.empty()) @@ -422,7 +425,12 @@ namespace { "Predicate = " << report.HANDLER(limit_).str()); if (info.second.tokens_remaining()) { - string display = args_to_predicate(info.second).first.text(); + info = args_to_predicate(info.second); + if (! info.first) + throw_(std::runtime_error, + _("Invalid display predicate: %1") << join_args(args)); + + string display = info.first.text(); if (! display.empty()) report.HANDLER(display_).on(whence, display); -- cgit v1.2.3