From 80058dfe8fb384f6e1529afa810c6a9bd08cdf88 Mon Sep 17 00:00:00 2001 From: "Manuel Amador (Rudd-O)" Date: Sat, 6 Feb 2016 00:45:49 +0000 Subject: Ensure that parse errors produce useful RuntimeErrors for Python code. --- src/context.h | 1 + src/error.h | 5 +++-- src/global.h | 2 +- src/textual.cc | 7 ++++++- 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; } -- cgit v1.2.3 From d300dfefec6210a326bdd12f12be1a93db305dab Mon Sep 17 00:00:00 2001 From: "Manuel Amador (Rudd-O)" Date: Mon, 8 Feb 2016 04:58:01 +0000 Subject: Add parse error test --- test/python/JournalTest.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/python/JournalTest.py b/test/python/JournalTest.py index e65c671d..2565ede8 100644 --- a/test/python/JournalTest.py +++ b/test/python/JournalTest.py @@ -22,6 +22,24 @@ class JournalTestCase(unittest.TestCase): for post in journal.query("food"): self.assertEqual(str(post.account), "Expenses:Food") self.assertEqual(post.amount, Amount("$21.34")) + + def testParseError(self): + # TODO: ledger spits out parse errors to standard out. + # This should not happen, especially when the error + # has already been captured by a Python exception. + def fun(): + read_journal_from_string(""" +2012-03-01 KFC + Expenses:Food rsnetnirsnti + Assets:Cash +""") + self.assertRaises(RuntimeError, fun) + try: + fun() + except RuntimeError as e: + self.assertEquals(str(e).splitlines()[-1], + "No quantity specified for amount") + def suite(): return unittest.TestLoader().loadTestsFromTestCase(JournalTestCase) -- cgit v1.2.3 From 6cbe04ca85453291326a8db5a53a5eb4f1665b68 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Thu, 7 Apr 2016 00:15:09 +0200 Subject: Require correct feature In `ledger-matching.el' require `ledger-report' instead of `ldg-report'. That library was renamed like all the others. --- contrib/raw/ledger-matching.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/raw/ledger-matching.el b/contrib/raw/ledger-matching.el index b8e62dd9..36006a69 100644 --- a/contrib/raw/ledger-matching.el +++ b/contrib/raw/ledger-matching.el @@ -1,6 +1,6 @@ ;; This library is intended to allow me to view a receipt on one panel, and tie it to ledger transactions in another -(require 'ldg-report) +(require 'ledger-report) (defgroup ledger-matching nil "Ledger image matching") -- cgit v1.2.3 From 097abf2be5bb1260b27ce98d66d813f279acf48f Mon Sep 17 00:00:00 2001 From: RĂ©mi Vanicat Date: Sat, 28 May 2016 15:35:09 +0200 Subject: inhibit read only when inserting in *Ledger Error* When ledger-exec-handle-error is called a second time, it try to insert the error in a buffer that is already read-only. inhibit-read-only permit the insertion. --- lisp/ledger-exec.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/ledger-exec.el b/lisp/ledger-exec.el index 4ba9134d..75a05262 100644 --- a/lisp/ledger-exec.el +++ b/lisp/ledger-exec.el @@ -48,7 +48,8 @@ (defun ledger-exec-handle-error (ledger-output) "Deal with ledger errors contained in LEDGER-OUTPUT." (with-current-buffer (get-buffer-create "*Ledger Error*") - (insert-buffer-substring ledger-output) + (let ((inhibit-read-only t)) + (insert-buffer-substring ledger-output)) (view-mode) (setq buffer-read-only t))) -- cgit v1.2.3