Module: check_mk
Branch: master
Commit: 0ae551cccac14429a90c62194b820fd24bbbfb58
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0ae551cccac144…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jul 23 09:53:17 2018 +0200
Fixed handling of exceptions with non ascii characters in messages
Exceptions may use str or unicode messages which both may contain
non ascii characters. The crash handling and exception logging did
not handle all cases correctly resuling in subsequent encoding or
decoding related exceptions.
The logging and crash handling code has now been changed to get the
message from the exception and decode it to a unicode string before
processing it.
Change-Id: I6a084fef8b07b98719a2549a7926946cb455d1b7
---
cmk/crash_reporting.py | 8 +++++++-
cmk/gui/crash_reporting.py | 9 ++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/cmk/crash_reporting.py b/cmk/crash_reporting.py
index 4f17ffc..414ec73 100644
--- a/cmk/crash_reporting.py
+++ b/cmk/crash_reporting.py
@@ -79,6 +79,12 @@ def create_crash_info(crash_type, details=None, version=None):
if exc_type.__name__ == "MKParseFunctionError":
tb_list += traceback.extract_tb(exc_value.exc_info()[2])
+ # Unify different string types from exception messages to a unicode string
+ try:
+ exc_txt = unicode(exc_value)
+ except UnicodeDecodeError:
+ exc_txt = str(exc_value).decode("utf-8")
+
return {
"crash_type" : crash_type,
"time" : time.time(),
@@ -89,7 +95,7 @@ def create_crash_info(crash_type, details=None, version=None):
"python_version": sys.version,
"python_paths" : sys.path,
"exc_type" : exc_type.__name__,
- "exc_value" : "%s" % exc_value,
+ "exc_value" : exc_txt,
"exc_traceback" : tb_list,
"local_vars" : get_local_vars_of_last_exception(),
"details" : details,
diff --git a/cmk/gui/crash_reporting.py b/cmk/gui/crash_reporting.py
index 1f4ce7b..a9cd960 100644
--- a/cmk/gui/crash_reporting.py
+++ b/cmk/gui/crash_reporting.py
@@ -85,7 +85,14 @@ def page_crashed(what):
details = {}
if what == "gui":
- html.show_error("<b>%s:</b> %s" % (_("Internal
error"), sys.exc_info()[1]))
+ # Unify different string types from exception messages to a unicode string
+ exc_value = sys.exc_info()[1]
+ try:
+ exc_txt = unicode(exc_value)
+ except UnicodeDecodeError:
+ exc_txt = str(exc_value).decode("utf-8")
+
+ html.show_error("<b>%s:</b> %s" % (_("Internal
error"), exc_txt))
html.p(_("An internal error occured while processing your request. "
"You can report this issue to the Check_MK team to help "
"fixing this issue. Please use the form below for
reporting."))