1. Michael Bayer
  2. mako
  3. Issues

Issues

Issue #132 resolved

traceback bug with closures

Michael Bayer
repo owner created an issue

When it lists the backtrace, like:

('/home/wacky/build/Vigilia/env/lib/python2.6/site-packages/pylons/controllers/core.py', 105, '_inspect_call', 'result = self._perform_call(func, args)'), ('/home/wacky/build/Vigilia/env/lib/python2.6/site-packages/pylons/controllers/core.py', 57, '_perform_call', 'return func(args)'), ('<string>', 2, 'edit_album', None), ('/home/wacky/build/Vigilia/vigilia/lib/base.py', 88, 'wrapper', 'return func(self, *args, kwargs)'),

notice the <string>, 'edit_album', and None object. This None object is the cause. It should be converted to string, or Mako should know how to deal with it.

We get a None there when the function is a closure, or a returned function that dynamically generated, which is the case with most decorators.

The solution is a two-liner:

diff -r 6cf6461d778243d8a8986c658eb2246e5939bdce mako/exceptions.py --- a/mako/exceptions.py Tue Apr 13 10:07:04 2010 -0400 +++ b/mako/exceptions.py Sat Apr 17 16:28:52 2010 -0400 @@ -152,6 +152,8 @@ 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: }}

Comments (3)

  1. Michael Bayer reporter

    we suspect this is the bug:

    def test_format_closures(self): try: exec "def foo():"\ " raise RuntimeError('test')"\ in locals() foo() except: html_error = exceptions.html_error_template().render() print html_error

  2. Log in to comment