summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py')
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py
index 79a001fe..f7533648 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py
@@ -13,19 +13,22 @@ except NameError:
class STLError(Exception):
def __init__ (self, msg):
self.msg = str(msg)
- self.tb = traceback.extract_stack()
+ self.stack = traceback.extract_stack()
def __str__ (self):
+ self.tb = traceback.extract_tb(sys.exc_info()[2])
+ if not self.tb:
+ return self.msg
s = format_text("\n******\n", 'bold')
- s += format_text('\nSummary error report:\n\n', 'underline')
- s += format_text(self.msg + '\n', 'bold')
-
- s += format_text("\nFull error report:\n\n", 'underline')
-
- for line in reversed(self.tb[:-1]):
+ s += format_text("\nException stack (most recent call last):\n\n", 'underline')
+
+ for i, line in enumerate(self.tb):
fname, lineno, func, src = os.path.split(line[0])[1], line[1], line[2], line[3]
- s += " {:<50} - '{}'\n".format(format_text(fname, 'bold') + ':' + format_text(lineno, 'bold'), format_text(src.strip(), 'bold'))
+ s += "#{:<2} {:<50} - '{}'\n".format(len(self.tb) - i - 1, format_text(fname, 'bold') + ':' + format_text(lineno, 'bold'), format_text(src.strip(), 'bold'))
+
+ s += format_text('\nSummary error message:\n\n', 'underline')
+ s += format_text(self.msg + '\n', 'bold')
return s