Issue #8924: logging: Improved error handling for Unicode in exception text.
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 239ae61..80ec672 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -473,7 +473,13 @@
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
#
diff --git a/Misc/NEWS b/Misc/NEWS
index 78d8cc7..0d35399 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,7 @@
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.