Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#1852 closed enhancement (fixed)

Print original exception when an unknown error occurs in template

Reported by: nnorwitz@… Owned by: adrian
Component: Template system Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

We had a problem when we updated a Model, but not the DB. Loading the template failed and we got a useless error message because of catching the original exception and wrapping it. Only the TemplateSyntaxError was printed, not the original exception which was very misleading. This was with 0.91, but HEAD has the same issue. Below is a patch that fixes the problem. I didn't see a way to upload a file as a patch.

--- template/init.py.orig 2006-05-12 11:14:27.000000000 -0700
+++ template/init.py 2006-05-12 11:14:00.000000000 -0700
@@ -90,7 +90,20 @@

builtins = []


class TemplateSyntaxError(Exception):

  • pass

+ def str(self):
+ try:
+ import cStringIO as StringIO
+ except ImportError:
+ import StringIO
+ output = StringIO.StringIO()
+ output.write(Exception.str(self))
+ # Check if we wrapped an exception and print that too.
+ if hasattr(self, 'exc_info'):
+ import traceback
+ output.write('\n\nOriginal ')
+ e = self.exc_info
+ traceback.print_exception(e[0], e[1], e[2], 500, output)
+ return output.getvalue()

class ContextPopException(Exception):

"pop() has been called more times than push()"

Attachments (1)

template-print.diff (839 bytes) - added by anonymous 8 years ago.

Download all attachments as: .zip

Change History (2)

Changed 8 years ago by anonymous

comment:1 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [2906]) Fixed #1852 -- Improved TemplateSyntaxError to display the original exception if str() of the exception raises an exception in itself. Thanks, nnorwitz@…

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.