From 936efc791a9d97e4d4a9db386dc419b7ab30dfab Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Fri, 11 Jun 2010 22:56:50 +0000 Subject: [PATCH] Issue #8924: logging: Improved error handling for Unicode in exception text. --- Lib/logging/__init__.py | 8 +++++++- Misc/NEWS | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 239ae61fad..80ec6724e4 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -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 # diff --git a/Misc/NEWS b/Misc/NEWS index 78d8cc70f9..0d353994ec 100644 --- 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. -- 2.50.1