From a4930c74cbcb403c118495f56f8d3778976f2955 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Mon, 31 Oct 2022 13:49:19 +0100 Subject: Make --backtrace show non-SpackError backtraces (#33540) --- lib/spack/spack/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/main.py b/lib/spack/spack/main.py index 998d0e2022..4c3f19d75d 100644 --- a/lib/spack/spack/main.py +++ b/lib/spack/spack/main.py @@ -107,6 +107,9 @@ required_command_properties = ["level", "section", "description"] spack_working_dir = None spack_ld_library_path = os.environ.get("LD_LIBRARY_PATH", "") +#: Whether to print backtraces on error +SHOW_BACKTRACE = False + def set_working_dir(): """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: spack.error.debug = True + global SHOW_BACKTRACE + SHOW_BACKTRACE = True if args.debug: spack.util.debug.register_interrupt_handler() @@ -1002,7 +1007,7 @@ def main(argv=None): e.die() # gracefully die on any SpackErrors except KeyboardInterrupt: - if spack.config.get("config:debug"): + if spack.config.get("config:debug") or SHOW_BACKTRACE: raise sys.stderr.write("\n") tty.error("Keyboard interrupt.") @@ -1012,12 +1017,12 @@ def main(argv=None): return signal.SIGINT except SystemExit as e: - if spack.config.get("config:debug"): + if spack.config.get("config:debug") or SHOW_BACKTRACE: traceback.print_exc() return e.code except Exception as e: - if spack.config.get("config:debug"): + if spack.config.get("config:debug") or SHOW_BACKTRACE: raise tty.error(e) return 3 -- cgit v1.2.3-60-g2f50