From c02f3a19da8867c86cfb5646a4de25af5eee5bc2 Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Tue, 7 Feb 2017 21:10:20 +0200 Subject: STL API: change STLError representation Change-Id: I1d4f4f5b11764f720713811c019802eeac3f5071 Signed-off-by: Yaroslav Brustinov --- .../stl/trex_stl_lib/trex_stl_exceptions.py | 19 +++++++++++-------- 1 file 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 -- cgit 1.2.3-korg