[Checkins] SVN: z3c.pt/trunk/ Carry over traceback info from first
template exception.
Malthe Borch
mborch at gmail.com
Wed Mar 26 10:47:32 EDT 2008
Log message for revision 84954:
Carry over traceback info from first template exception.
Changed:
U z3c.pt/trunk/docs/HISTORY.txt
U z3c.pt/trunk/z3c/pt/README.txt
U z3c.pt/trunk/z3c/pt/template.py
-=-
Modified: z3c.pt/trunk/docs/HISTORY.txt
===================================================================
--- z3c.pt/trunk/docs/HISTORY.txt 2008-03-26 12:55:14 UTC (rev 84953)
+++ z3c.pt/trunk/docs/HISTORY.txt 2008-03-26 14:47:31 UTC (rev 84954)
@@ -4,6 +4,9 @@
Version 0.8.x
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- Made sure the traceback from the *first* template exception
+ is carried over to __traceback_info__
+
- Added template source annotations on exceptions raised while
rendering a template.
Modified: z3c.pt/trunk/z3c/pt/README.txt
===================================================================
--- z3c.pt/trunk/z3c/pt/README.txt 2008-03-26 12:55:14 UTC (rev 84953)
+++ z3c.pt/trunk/z3c/pt/README.txt 2008-03-26 14:47:31 UTC (rev 84954)
@@ -150,7 +150,7 @@
... </div>""").render()
Traceback (most recent call last):
...
- TypeError: While rendering template, range expected at least 1 arguments, got 0 ("range()").
+ TypeError: range expected at least 1 arguments, got 0
Exception while evaluating definition:
@@ -162,7 +162,7 @@
... </div>""").render()
Traceback (most recent call last):
...
- TypeError: While rendering template, range expected at least 1 arguments, got 0 ("range()").
+ TypeError: range expected at least 1 arguments, got 0
Exception while evaluating interpolation:
@@ -174,4 +174,4 @@
... </div>""").render()
Traceback (most recent call last):
...
- TypeError: While rendering template, range expected at least 1 arguments, got 0 ("range()").
+ TypeError: range expected at least 1 arguments, got 0
Modified: z3c.pt/trunk/z3c/pt/template.py
===================================================================
--- z3c.pt/trunk/z3c/pt/template.py 2008-03-26 12:55:14 UTC (rev 84953)
+++ z3c.pt/trunk/z3c/pt/template.py 2008-03-26 14:47:31 UTC (rev 84954)
@@ -1,7 +1,8 @@
import os
import sys
import codegen
-
+import traceback
+
class BaseTemplate(object):
registry = {}
default_expression = 'python'
@@ -45,9 +46,12 @@
try:
return template(**kwargs)
except Exception, e:
+ __traceback_info__ = getattr(e, '__traceback_info__', None)
+ if __traceback_info__ is not None:
+ raise e
+
etype, value, tb = sys.exc_info()
lineno = tb.tb_next.tb_lineno-1
-
annotations = self.annotations
while lineno >= 0:
@@ -57,14 +61,22 @@
lineno -= 1
else:
- annotation = None
+ annotation = "n/a"
+
+ e.__traceback_info__ = "While rendering %s, an exception was "\
+ "raised evaluating ``%s``:\n\n" % \
+ (repr(self), str(annotation))
- raise e.__class__(
- "While rendering template, %s (\"%s\")." % (str(e), str(annotation)))
+ e.__traceback_info__ += "".join(traceback.format_tb(tb))
+
+ raise e
def __call__(self, **kwargs):
return self.render(**kwargs)
+ def __repr__(self):
+ return u"<%s %d>" % (self.__class__.__name__, id(self))
+
class BaseTemplateFile(BaseTemplate):
def __init__(self, filename):
if not os.path.isabs(filename):
@@ -113,3 +125,6 @@
return os.path.getmtime(self.filename)
except OSError:
return 0
+
+ def __repr__(self):
+ return u"<%s %s>" % (self.__class__.__name__, self.filename)
More information about the Checkins
mailing list