summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Amador (Rudd-O) <rudd-o@rudd-o.com>2016-02-06 00:45:49 +0000
committerManuel Amador (Rudd-O) <rudd-o@rudd-o.com>2016-02-06 00:45:49 +0000
commit80058dfe8fb384f6e1529afa810c6a9bd08cdf88 (patch)
treec989f987b3a47854867f026ca6a9630cafe2b2fc
parent11151414aa70f6673b2464e938ae930d8674c915 (diff)
downloadfork-ledger-80058dfe8fb384f6e1529afa810c6a9bd08cdf88.tar.gz
fork-ledger-80058dfe8fb384f6e1529afa810c6a9bd08cdf88.tar.bz2
fork-ledger-80058dfe8fb384f6e1529afa810c6a9bd08cdf88.zip
Ensure that parse errors produce useful RuntimeErrors for Python code.
-rw-r--r--src/context.h1
-rw-r--r--src/error.h5
-rw-r--r--src/global.h2
-rw-r--r--src/textual.cc7
4 files changed, 11 insertions, 4 deletions
diff --git a/src/context.h b/src/context.h
index 61797dc4..603898f4 100644
--- a/src/context.h
+++ b/src/context.h
@@ -70,6 +70,7 @@ public:
std::size_t errors;
std::size_t count;
std::size_t sequence;
+ std::string last;
explicit parse_context_t(const path& cwd)
: current_directory(cwd), master(NULL), scope(NULL),
diff --git a/src/error.h b/src/error.h
index 73a0e395..26cbfafb 100644
--- a/src/error.h
+++ b/src/error.h
@@ -95,8 +95,9 @@ string source_context(const path& file,
struct error_count {
std::size_t count;
- explicit error_count(std::size_t _count) : count(_count) {}
- const char * what() const { return ""; }
+ std::string message;
+ explicit error_count(std::size_t _count, std::string _msg) : count(_count), message(_msg) {}
+ const char * what() const { return message.c_str(); }
};
} // namespace ledger
diff --git a/src/global.h b/src/global.h
index 1a4a3076..42464e35 100644
--- a/src/global.h
+++ b/src/global.h
@@ -166,7 +166,7 @@ See LICENSE file included with the distribution for details and disclaimer.");
OPTION_(global_scope_t, version, DO() { // -v
parent->show_version_info(std::cout);
- throw error_count(0); // exit immediately
+ throw error_count(0, ""); // exit immediately
});
};
diff --git a/src/textual.cc b/src/textual.cc
index ccd87ca0..c97b8b01 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -282,6 +282,10 @@ void instance_t::parse()
std::cerr << _("Error: ") << err.what() << std::endl;
context.errors++;
+ if (! current_context.empty())
+ context.last = current_context + "\n" + err.what();
+ else
+ context.last = err.what();
}
}
@@ -1998,7 +2002,8 @@ std::size_t journal_t::read_textual(parse_context_stack_t& context_stack)
TRACE_FINISH(parsing_total, 1);
if (context_stack.get_current().errors > 0)
- throw error_count(context_stack.get_current().errors);
+ throw error_count(context_stack.get_current().errors,
+ context_stack.get_current().last);
return context_stack.get_current().count;
}