summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2017-02-07 21:10:20 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2017-02-07 21:10:20 +0200
commitc02f3a19da8867c86cfb5646a4de25af5eee5bc2 (patch)
tree60264d4b14b83d9a31bd47604199d5d57682d3e5 /scripts/automation/trex_control_plane/stl
parent23089b8974f72a00baa6cec8b6047a9b958b655c (diff)
STL API: change STLError representation
Change-Id: I1d4f4f5b11764f720713811c019802eeac3f5071 Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl')
-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