diff options
author | Harmen Stoppels <me@harmenstoppels.nl> | 2024-10-19 15:45:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-19 15:45:59 +0200 |
commit | 9b8c06a049913ff15dc5eac7072da8137f51bf2d (patch) | |
tree | de85226c42464e9d17fbff5d490aedf4000c56f5 /lib | |
parent | 011ff48f82bf7bb6be685f4f573b870659c8762e (diff) | |
download | spack-9b8c06a049913ff15dc5eac7072da8137f51bf2d.tar.gz spack-9b8c06a049913ff15dc5eac7072da8137f51bf2d.tar.bz2 spack-9b8c06a049913ff15dc5eac7072da8137f51bf2d.tar.xz spack-9b8c06a049913ff15dc5eac7072da8137f51bf2d.zip |
spack external find: show backtrace on error when --backtrace (#47082)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/detection/path.py | 12 | ||||
-rw-r--r-- | lib/spack/spack/error.py | 3 | ||||
-rw-r--r-- | lib/spack/spack/main.py | 12 |
3 files changed, 16 insertions, 11 deletions
diff --git a/lib/spack/spack/detection/path.py b/lib/spack/spack/detection/path.py index e8081f6e3c..d529f94f29 100644 --- a/lib/spack/spack/detection/path.py +++ b/lib/spack/spack/detection/path.py @@ -11,6 +11,7 @@ import os import os.path import re import sys +import traceback import warnings from typing import Dict, Iterable, List, Optional, Set, Tuple, Type @@ -18,6 +19,7 @@ import llnl.util.filesystem import llnl.util.lang import llnl.util.tty +import spack.error import spack.spec import spack.util.elf as elf_utils import spack.util.environment @@ -274,8 +276,12 @@ class Finder: ) except Exception as e: specs = [] + if spack.error.SHOW_BACKTRACE: + details = traceback.format_exc() + else: + details = f"[{e.__class__.__name__}: {e}]" warnings.warn( - f'error detecting "{pkg.name}" from prefix {candidate_path} [{str(e)}]' + f'error detecting "{pkg.name}" from prefix {candidate_path}: {details}' ) if not specs: @@ -449,9 +455,9 @@ def by_path( llnl.util.tty.debug( f"[EXTERNAL DETECTION] Skipping {pkg_name}: timeout reached" ) - except Exception as e: + except Exception: llnl.util.tty.debug( - f"[EXTERNAL DETECTION] Skipping {pkg_name}: exception occured {e}" + f"[EXTERNAL DETECTION] Skipping {pkg_name}: {traceback.format_exc()}" ) return result diff --git a/lib/spack/spack/error.py b/lib/spack/spack/error.py index edb4b9e89f..45a39a4f20 100644 --- a/lib/spack/spack/error.py +++ b/lib/spack/spack/error.py @@ -12,6 +12,9 @@ import llnl.util.tty as tty #: this is module-scoped because it needs to be set very early debug = 0 +#: whether to show a backtrace when an error is printed, enabled with --backtrace. +SHOW_BACKTRACE = False + class SpackError(Exception): """This is the superclass for all Spack errors. diff --git a/lib/spack/spack/main.py b/lib/spack/spack/main.py index c0bb3d3355..7493e993ab 100644 --- a/lib/spack/spack/main.py +++ b/lib/spack/spack/main.py @@ -102,9 +102,6 @@ required_command_properties = ["level", "section", "description"] spack_ld_library_path = os.environ.get("LD_LIBRARY_PATH", "") -#: Whether to print backtraces on error -SHOW_BACKTRACE = False - def add_all_commands(parser): """Add all spack subcommands to the parser.""" @@ -527,8 +524,7 @@ def setup_main_options(args): if args.debug or args.backtrace: spack.error.debug = True - global SHOW_BACKTRACE - SHOW_BACKTRACE = True + spack.error.SHOW_BACKTRACE = True if args.debug: spack.util.debug.register_interrupt_handler() @@ -1021,19 +1017,19 @@ def main(argv=None): e.die() # gracefully die on any SpackErrors except KeyboardInterrupt: - if spack.config.get("config:debug") or SHOW_BACKTRACE: + if spack.config.get("config:debug") or spack.error.SHOW_BACKTRACE: raise sys.stderr.write("\n") tty.error("Keyboard interrupt.") return signal.SIGINT.value except SystemExit as e: - if spack.config.get("config:debug") or SHOW_BACKTRACE: + if spack.config.get("config:debug") or spack.error.SHOW_BACKTRACE: traceback.print_exc() return e.code except Exception as e: - if spack.config.get("config:debug") or SHOW_BACKTRACE: + if spack.config.get("config:debug") or spack.error.SHOW_BACKTRACE: raise tty.error(e) return 3 |