added error checking
This commit is contained in:
parent
0f2ed1f5e3
commit
b20ddba1d5
2 changed files with 58 additions and 15 deletions
40
main.cc
40
main.cc
|
|
@ -581,13 +581,45 @@ int main(int argc, char * argv[])
|
||||||
|
|
||||||
// Compile the sorting string
|
// Compile the sorting string
|
||||||
|
|
||||||
if (! sort_string.empty())
|
if (! sort_string.empty()) {
|
||||||
sort_order.reset(parse_value_expr(sort_string));
|
try {
|
||||||
|
std::istringstream stream(sort_string);
|
||||||
|
sort_order.reset(parse_value_expr(stream));
|
||||||
|
if (! stream.eof()) {
|
||||||
|
std::ostringstream err;
|
||||||
|
err << "Unexpected character '" << char(stream.peek()) << "'";
|
||||||
|
throw value_expr_error(err.str());
|
||||||
|
}
|
||||||
|
else if (! sort_order.get()) {
|
||||||
|
std::cerr << "Failed to parse sort criteria!" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const value_expr_error& err) {
|
||||||
|
std::cerr << "Error in sort criteria: " << err.what() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Setup the meaning of %t and %T, used in format strings
|
// Setup the meaning of %t and %T, used in format strings
|
||||||
|
|
||||||
format_t::value_expr.reset(parse_value_expr(value_expr));
|
try {
|
||||||
format_t::total_expr.reset(parse_value_expr(total_expr));
|
format_t::value_expr.reset(parse_value_expr(value_expr));
|
||||||
|
}
|
||||||
|
catch (const value_expr_error& err) {
|
||||||
|
std::cerr << "Error in amount (-t) specifier: " << err.what()
|
||||||
|
<< std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
format_t::total_expr.reset(parse_value_expr(total_expr));
|
||||||
|
}
|
||||||
|
catch (const value_expr_error& err) {
|
||||||
|
std::cerr << "Error in total (-T) specifier: " << err.what()
|
||||||
|
<< std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Now handle the command that was identified above.
|
// Now handle the command that was identified above.
|
||||||
|
|
||||||
|
|
|
||||||
33
valexpr.h
33
valexpr.h
|
|
@ -2,6 +2,7 @@
|
||||||
#define _EXPR_H
|
#define _EXPR_H
|
||||||
|
|
||||||
#include "ledger.h"
|
#include "ledger.h"
|
||||||
|
#include "error.h"
|
||||||
|
|
||||||
namespace ledger {
|
namespace ledger {
|
||||||
|
|
||||||
|
|
@ -128,19 +129,29 @@ class item_predicate
|
||||||
const value_expr_t * predicate;
|
const value_expr_t * predicate;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
item_predicate(const std::string& _predicate)
|
item_predicate(const std::string& _predicate) {
|
||||||
: predicate(_predicate.empty() ?
|
predicate = NULL;
|
||||||
NULL : parse_value_expr(_predicate)) {
|
if (! _predicate.empty()) {
|
||||||
#ifdef DEBUG_ENABLED
|
try {
|
||||||
DEBUG_CLASS("valexpr.predicate.parse");
|
DEBUG_CLASS("valexpr.predicate.parse");
|
||||||
|
|
||||||
DEBUG_PRINT_("parsing: '" << _predicate << "'");
|
DEBUG_PRINT_("parsing: '" << _predicate << "'");
|
||||||
if (DEBUG_() && ledger::debug_stream) {
|
predicate = parse_value_expr(_predicate);
|
||||||
*ledger::debug_stream << "dump: ";
|
|
||||||
dump_value_expr(*ledger::debug_stream, predicate);
|
#ifdef DEBUG_ENABLED
|
||||||
*ledger::debug_stream << std::endl;
|
if (DEBUG_() && ledger::debug_stream) {
|
||||||
}
|
*ledger::debug_stream << "dump: ";
|
||||||
|
dump_value_expr(*ledger::debug_stream, predicate);
|
||||||
|
*ledger::debug_stream << std::endl;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
catch (const value_expr_error& err) {
|
||||||
|
std::cerr << "Error in predicate '" << _predicate << "': "
|
||||||
|
<< err.what() << std::endl;
|
||||||
|
std::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
item_predicate(const value_expr_t * _predicate)
|
item_predicate(const value_expr_t * _predicate)
|
||||||
: predicate(_predicate) {}
|
: predicate(_predicate) {}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue