From 965db8806596539bc286077c3b70fc98e8b56ea1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 17 Oct 2013 14:14:47 +0530 Subject: [PATCH] Printout tracebacks in debug mode for exception during template processing --- src/calibre/db/locking.py | 2 ++ src/calibre/utils/formatter.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/calibre/db/locking.py b/src/calibre/db/locking.py index df27bbbb25..cc006f65f5 100644 --- a/src/calibre/db/locking.py +++ b/src/calibre/db/locking.py @@ -13,6 +13,8 @@ from calibre.utils.config_base import tweaks class LockingError(RuntimeError): + is_locking_error = True + def __init__(self, msg, extra=None): RuntimeError.__init__(self, msg) self.locking_debug_msg = extra diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index 2fa5901dde..34eb06a089 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -515,8 +515,8 @@ class TemplateFormatter(string.Formatter): try: ans = self.evaluate(fmt, [], kwargs).strip() except Exception as e: -# if DEBUG: -# traceback.print_exc() + if DEBUG and getattr(e, 'is_locking_error', False): + traceback.print_exc() ans = error_value + ' ' + e.message return ans @@ -529,7 +529,7 @@ class ValidateFormatter(TemplateFormatter): def validate(self, x): from calibre.ebooks.metadata.book.base import Metadata - self.book = Metadata(''); + self.book = Metadata('') return self.vformat(x, [], {}) validation_formatter = ValidateFormatter()