diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-05-15 04:24:48 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-05-15 04:24:48 +0000 |
| commit | 55c9e98d86e717a3da832fc309947d70a68ffdb0 (patch) | |
| tree | 26827fe15707ff7fbc1ec488004310d332b8704f /django | |
| parent | 51f6a9442c21d6288ccca9b8d9ebaf2f6ecd5b9d (diff) | |
Fixed #1852 -- Improved TemplateSyntaxError to display the original exception if str() of the exception raises an exception in itself. Thanks, nnorwitz@google.com
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2906 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/template/__init__.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/django/template/__init__.py b/django/template/__init__.py index e32200cccb..18dceff45c 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -91,7 +91,20 @@ libraries = {} 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 TemplateDoesNotExist(Exception): pass |
