From a8be1b562e82094c9ca59aef00b6276b4747226b Mon Sep 17 00:00:00 2001 From: Deniz Turgut Date: Sat, 29 Oct 2016 14:04:13 -0400 Subject: [PATCH] Fixes Exception name related bugs Fixes two bugs that was introduced by #1743: - First was the unnecessary exception name output when skipping content files if a required metadata wasn't available. It was `ERROR: Skipping ./demo.rst: could not find information about 'NameError: date'` and now should be `ERROR: Skipping ./demo.rst: could not find information about 'date'` - Second was a more serious issue. Improper string formatting in the logger resulted in implicit decoding and would break for non-ascii error messages. --- pelican/contents.py | 3 ++- pelican/log.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index 9b6aa971..1ded6cdb 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -473,5 +473,6 @@ def is_valid_content(content, f): return True except NameError as e: logger.error( - "Skipping %s: could not find information about '%s'", f, e) + "Skipping %s: could not find information about '%s'", + f, six.text_type(e)) return False diff --git a/pelican/log.py b/pelican/log.py index fe14a29b..cec07bf0 100644 --- a/pelican/log.py +++ b/pelican/log.py @@ -157,7 +157,7 @@ class SafeLogger(logging.Logger): so convert the message to unicode with the correct encoding ''' if isinstance(arg, Exception): - text = '%s: %s' % (arg.__class__.__name__, arg) + text = str('%s: %s') % (arg.__class__.__name__, arg) if six.PY2: text = text.decode(self._exc_encoding) return text