1
0
Fork 0
forked from github/pelican

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.
This commit is contained in:
Deniz Turgut 2016-10-29 14:04:13 -04:00
commit a8be1b562e
2 changed files with 3 additions and 2 deletions

View file

@ -473,5 +473,6 @@ def is_valid_content(content, f):
return True return True
except NameError as e: except NameError as e:
logger.error( 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 return False

View file

@ -157,7 +157,7 @@ class SafeLogger(logging.Logger):
so convert the message to unicode with the correct encoding so convert the message to unicode with the correct encoding
''' '''
if isinstance(arg, Exception): if isinstance(arg, Exception):
text = '%s: %s' % (arg.__class__.__name__, arg) text = str('%s: %s') % (arg.__class__.__name__, arg)
if six.PY2: if six.PY2:
text = text.decode(self._exc_encoding) text = text.decode(self._exc_encoding)
return text return text