Printout tracebacks in debug mode for exception during template processing

This commit is contained in:
Kovid Goyal 2013-10-17 14:14:47 +05:30
parent 73e7ddcefe
commit 965db88065
2 changed files with 5 additions and 3 deletions

View File

@ -13,6 +13,8 @@ from calibre.utils.config_base import tweaks
class LockingError(RuntimeError): class LockingError(RuntimeError):
is_locking_error = True
def __init__(self, msg, extra=None): def __init__(self, msg, extra=None):
RuntimeError.__init__(self, msg) RuntimeError.__init__(self, msg)
self.locking_debug_msg = extra self.locking_debug_msg = extra

View File

@ -515,8 +515,8 @@ class TemplateFormatter(string.Formatter):
try: try:
ans = self.evaluate(fmt, [], kwargs).strip() ans = self.evaluate(fmt, [], kwargs).strip()
except Exception as e: except Exception as e:
# if DEBUG: if DEBUG and getattr(e, 'is_locking_error', False):
# traceback.print_exc() traceback.print_exc()
ans = error_value + ' ' + e.message ans = error_value + ' ' + e.message
return ans return ans
@ -529,7 +529,7 @@ class ValidateFormatter(TemplateFormatter):
def validate(self, x): def validate(self, x):
from calibre.ebooks.metadata.book.base import Metadata from calibre.ebooks.metadata.book.base import Metadata
self.book = Metadata(''); self.book = Metadata('')
return self.vformat(x, [], {}) return self.vformat(x, [], {})
validation_formatter = ValidateFormatter() validation_formatter = ValidateFormatter()