simplify error handling using language features

This commit is contained in:
Gregory Becker
2020-03-27 17:46:52 -07:00
committed by Tamara Dahlgren
parent fdb8a59bae
commit ba58ae9118
2 changed files with 2 additions and 24 deletions

View File

@@ -16,28 +16,6 @@
debug = False
def re_raise(e, exc_info=None):
"""Re-raise an exception with it's original context."""
exc_type, context, tb = sys.exc_info()
# construct arguments to re-raise error from type
args = []
if hasattr(e, 'args'):
args.extend(e.args)
if hasattr(e, 'message') and e.message not in e.args:
args.append(e.message)
if hasattr(e, 'long_message'):
args.append(str(e.long_message))
if sys.version_info[0] < 3:
# ugly hack: exec to avoid the fact this is a syntax
# error in python 3
exec("raise exc_type(*args), None, tb",
globals(), locals())
else:
raise exc_type(*args).with_traceback(tb)
class SpackError(Exception):
"""This is the superclass for all Spack errors.
Subclasses can be found in the modules they have to do with.

View File

@@ -1652,7 +1652,7 @@ def test_process():
print('Error: %s' % e)
import traceback
traceback.print_tb(exc_info[2])
spack.error.re_raise(e)
raise # re-raise the same error/traceback
else:
# cleanup test directory on success
if remove_directory:
@@ -1699,7 +1699,7 @@ def run_test(self, exe, options=[], expected=[], status=None):
output = str(err)
status_msg = 'exited with status {0}'.format(status)
if status_msg not in output:
spack.error.re_raise(err)
raise # re-raise the same error/traceback
def unit_test_check(self):
"""Hook for unit tests to assert things about package internals.