From 34c2513d4a12d0a68c72bba4f9dfd3fc663c5553 Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Tue, 1 Jun 2021 07:00:08 +0000 Subject: [PATCH] [ci][getpiplineinfo] improve traceback handling --- bin/util/common.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bin/util/common.py b/bin/util/common.py index cb35d0975d..70296eba3b 100644 --- a/bin/util/common.py +++ b/bin/util/common.py @@ -2,6 +2,7 @@ import os import sys import functools import subprocess +import traceback def getCommandErrorHints(command): @@ -19,19 +20,19 @@ def runCommand(command, suppressTraceBack=False, errorMessage=''): shell=True, check=True, text=True, capture_output=True).stdout except Exception: + eType, eValue, eTraceback = sys.exc_info() if suppressTraceBack: - sys.excepthook(Exception, Exception(errorMessage), None) - elif not errorMessage: + traceback.print_exception(eType, eType(errorMessage), None) + elif errorMessage: + traceback.print_exception(eType, eType(errorMessage), eTraceback) + else: print("An error occurred during subprocess run:") print("-- command: {}".format(command)) print("-- folder: {}".format(os.getcwd())) - print("-- error: {}".format(sys.exc_info()[1])) + traceback.print_exception(eType, eValue, eTraceback) hints = getCommandErrorHints(command) if hints is not None: print(hints) - raise - else: - raise Exception(errorMessage) # decorator to call function from within the given path -- GitLab