From f753d3366556294b23a67739de281895e8b44681 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 | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index ba40067b61..b48bee85bd 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -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 # diff --git a/Misc/NEWS b/Misc/NEWS index 7ab2d91de4..fee5682cd4 100644 --- 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. -- 2.50.1