]> granicus.if.org Git - python/commitdiff
Issue #8924: logging: Improved error handling for Unicode in exception text.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Fri, 11 Jun 2010 22:56:50 +0000 (22:56 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Fri, 11 Jun 2010 22:56:50 +0000 (22:56 +0000)
Lib/logging/__init__.py
Misc/NEWS

index 239ae61fadbaeb1adee5a7b4ce05f4c6b3d1b8de..80ec6724e44c3d091e6120a6eeebfa47aecc1907 100644 (file)
@@ -473,7 +473,13 @@ class Formatter(object):
         if record.exc_text:
             if s[-1:] != "\n":
                 s = s + "\n"
-            s = s + record.exc_text
+            try:
+                s = s + record.exc_text
+            except UnicodeError:
+                # Sometimes filenames have non-ASCII chars, which can lead
+                # to errors when s is Unicode and record.exc_text is str
+                # See issue 8924
+                s = s + record.exc_text.decode(sys.getfilesystemencoding())
         return s
 
 #
index 78d8cc70f951f03f0fe98754135a521d5ce1bc87..0d353994ece6e140db2c0949acd16b9d7ed96ad2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,7 @@ Core and Builtins
 
 Library
 -------
+- Issue #8924: logging: Improved error handling for Unicode in exception text.
 
 - Issue #8948: cleanup functions and class / module setups and teardowns are
   now honored in unittest debug methods.