Module: check_mk
Branch: master
Commit: dc789110f9d476c2f73507e6e20c1286e167b5d0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dc789110f9d476…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Apr 27 16:05:42 2018 +0200
MKParseFunctionError: Fixed formating original trace
Change-Id: Ib0d52f82b78547e049f017664a2c76e2bbfeffa4
---
cmk/crash_reporting.py | 14 +++++++++++++-
cmk_base/exceptions.py | 4 +++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/cmk/crash_reporting.py b/cmk/crash_reporting.py
index 467994a..4f17ffc 100644
--- a/cmk/crash_reporting.py
+++ b/cmk/crash_reporting.py
@@ -67,6 +67,18 @@ def create_crash_info(crash_type, details=None, version=None):
exc_type, exc_value, exc_traceback = sys.exc_info()
+ tb_list = traceback.extract_tb(exc_traceback)
+
+ # MKParseFunctionError() are re raised exceptions originating from the
+ # parse functions of checks. They have the original traceback object saved.
+ # The formated stack of these tracebacks is somehow relative to the calling
+ # function. To get the full stack trace instead of this relative one we need
+ # to concatenate the traceback of the MKParseFunctionError() and the original
+ # exception.
+ # Re-raising exceptions will be much easier with Python 3.x.
+ if exc_type.__name__ == "MKParseFunctionError":
+ tb_list += traceback.extract_tb(exc_value.exc_info()[2])
+
return {
"crash_type" : crash_type,
"time" : time.time(),
@@ -78,7 +90,7 @@ def create_crash_info(crash_type, details=None, version=None):
"python_paths" : sys.path,
"exc_type" : exc_type.__name__,
"exc_value" : "%s" % exc_value,
- "exc_traceback" : traceback.extract_tb(exc_traceback),
+ "exc_traceback" : tb_list,
"local_vars" : get_local_vars_of_last_exception(),
"details" : details,
}
diff --git a/cmk_base/exceptions.py b/cmk_base/exceptions.py
index 5592009..3f89c01 100644
--- a/cmk_base/exceptions.py
+++ b/cmk_base/exceptions.py
@@ -27,6 +27,8 @@
# TODO: Inherit from cmk.MKGeneralException?
# TODO: Cleanup self.reason to use .args of standard exceptions
+import traceback
+
from cmk.exceptions import MKGeneralException as _MKGeneralException
class MKAgentError(Exception):
@@ -59,7 +61,7 @@ class MKParseFunctionError(Exception):
return self.exception_type, self.exception, self.backtrace
def __str__(self):
- return "%s\n%s" % (self.exception, self.backtrace)
+ return "%r\n%s" % (self.exception,
"".join(traceback.format_tb(self.backtrace)))