Make --backtrace show non-SpackError backtraces (#33540)

This commit is contained in:
Harmen Stoppels 2022-10-31 13:49:19 +01:00 committed by GitHub
parent 1ab888cdc1
commit a4930c74cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -107,6 +107,9 @@
spack_working_dir = None spack_working_dir = None
spack_ld_library_path = os.environ.get("LD_LIBRARY_PATH", "") spack_ld_library_path = os.environ.get("LD_LIBRARY_PATH", "")
#: Whether to print backtraces on error
SHOW_BACKTRACE = False
def set_working_dir(): def set_working_dir():
"""Change the working directory to getcwd, or spack prefix if no cwd.""" """Change the working directory to getcwd, or spack prefix if no cwd."""
@ -569,6 +572,8 @@ def setup_main_options(args):
if args.debug or args.backtrace: if args.debug or args.backtrace:
spack.error.debug = True spack.error.debug = True
global SHOW_BACKTRACE
SHOW_BACKTRACE = True
if args.debug: if args.debug:
spack.util.debug.register_interrupt_handler() spack.util.debug.register_interrupt_handler()
@ -1002,7 +1007,7 @@ def main(argv=None):
e.die() # gracefully die on any SpackErrors e.die() # gracefully die on any SpackErrors
except KeyboardInterrupt: except KeyboardInterrupt:
if spack.config.get("config:debug"): if spack.config.get("config:debug") or SHOW_BACKTRACE:
raise raise
sys.stderr.write("\n") sys.stderr.write("\n")
tty.error("Keyboard interrupt.") tty.error("Keyboard interrupt.")
@ -1012,12 +1017,12 @@ def main(argv=None):
return signal.SIGINT return signal.SIGINT
except SystemExit as e: except SystemExit as e:
if spack.config.get("config:debug"): if spack.config.get("config:debug") or SHOW_BACKTRACE:
traceback.print_exc() traceback.print_exc()
return e.code return e.code
except Exception as e: except Exception as e:
if spack.config.get("config:debug"): if spack.config.get("config:debug") or SHOW_BACKTRACE:
raise raise
tty.error(e) tty.error(e)
return 3 return 3