]> 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 ba40067b6132cda06e9e5d279c54326bf3691d6f..b48bee85bd07bfe1a52e59417227f31ee742bb8b 100644 (file)
@@ -445,7 +445,13 @@ class Formatter:
         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 7ab2d91de45963012bf6afaf4a37910abc61d541..fee5682cd4319d3d52c017ef4ddd73b7c41948b4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -71,6 +71,8 @@ C-API
 Library
 -------
 
+- Issue #8924: logging: Improved error handling for Unicode in exception text.
+
 - Fix codecs.escape_encode to return the correct consumed size.
 
 - Issue #6470: Drop UNC prefix in FixTk.