From 68c722954981c3eae3929ceb1b62d7bff7b7ba96 Mon Sep 17 00:00:00 2001 From: Mike Bayer <mike_mp@zzzcomputing.com> Date: Sat, 17 Apr 2010 16:55:52 -0400 Subject: [PATCH] - Fixed error formatting when a stacktrace line contains no line number, as in when inside an eval/exec-generated function. [ticket:132] --- CHANGES | 5 +++++ mako/exceptions.py | 2 ++ test/test_exceptions.py | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/CHANGES b/CHANGES index 9af7147..0668542 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,11 @@ - Fixed broken @property decorator on template.last_modified + +- Fixed error formatting when a stacktrace + line contains no line number, as in when + inside an eval/exec-generated function. + [ticket:132] 0.3.2 - Calling a def from the top, via diff --git a/mako/exceptions.py b/mako/exceptions.py index c0d7fd9..0c1f844 100644 --- a/mako/exceptions.py +++ b/mako/exceptions.py @@ -152,6 +152,8 @@ class RichTraceback(object): rawrecords = traceback.extract_tb(trcback) new_trcback = [] for filename, lineno, function, line in rawrecords: + if not line: + line = '' try: (line_map, template_lines) = mods[filename] except KeyError: diff --git a/test/test_exceptions.py b/test/test_exceptions.py index 22f879d..ab2f8e4 100644 --- a/test/test_exceptions.py +++ b/test/test_exceptions.py @@ -73,6 +73,16 @@ ${u'привет'} assert False, ("This function should trigger a CompileException, " "but didn't") + def test_format_closures(self): + try: + exec "def foo():"\ + " raise RuntimeError('test')"\ + in locals() + foo() + except: + html_error = exceptions.html_error_template().render() + assert "RuntimeError: test" in html_error + def test_py_utf8_html_error_template(self): try: foo = u'日本' -- GitLab