spack external find: show backtrace on error when --backtrace (#47082)
This commit is contained in:
parent
011ff48f82
commit
9b8c06a049
@ -11,6 +11,7 @@
|
|||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
import warnings
|
import warnings
|
||||||
from typing import Dict, Iterable, List, Optional, Set, Tuple, Type
|
from typing import Dict, Iterable, List, Optional, Set, Tuple, Type
|
||||||
|
|
||||||
@ -18,6 +19,7 @@
|
|||||||
import llnl.util.lang
|
import llnl.util.lang
|
||||||
import llnl.util.tty
|
import llnl.util.tty
|
||||||
|
|
||||||
|
import spack.error
|
||||||
import spack.spec
|
import spack.spec
|
||||||
import spack.util.elf as elf_utils
|
import spack.util.elf as elf_utils
|
||||||
import spack.util.environment
|
import spack.util.environment
|
||||||
@ -274,8 +276,12 @@ def detect_specs(
|
|||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
specs = []
|
specs = []
|
||||||
|
if spack.error.SHOW_BACKTRACE:
|
||||||
|
details = traceback.format_exc()
|
||||||
|
else:
|
||||||
|
details = f"[{e.__class__.__name__}: {e}]"
|
||||||
warnings.warn(
|
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:
|
if not specs:
|
||||||
@ -449,9 +455,9 @@ def by_path(
|
|||||||
llnl.util.tty.debug(
|
llnl.util.tty.debug(
|
||||||
f"[EXTERNAL DETECTION] Skipping {pkg_name}: timeout reached"
|
f"[EXTERNAL DETECTION] Skipping {pkg_name}: timeout reached"
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
llnl.util.tty.debug(
|
llnl.util.tty.debug(
|
||||||
f"[EXTERNAL DETECTION] Skipping {pkg_name}: exception occured {e}"
|
f"[EXTERNAL DETECTION] Skipping {pkg_name}: {traceback.format_exc()}"
|
||||||
)
|
)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
#: this is module-scoped because it needs to be set very early
|
#: this is module-scoped because it needs to be set very early
|
||||||
debug = 0
|
debug = 0
|
||||||
|
|
||||||
|
#: whether to show a backtrace when an error is printed, enabled with --backtrace.
|
||||||
|
SHOW_BACKTRACE = False
|
||||||
|
|
||||||
|
|
||||||
class SpackError(Exception):
|
class SpackError(Exception):
|
||||||
"""This is the superclass for all Spack errors.
|
"""This is the superclass for all Spack errors.
|
||||||
|
@ -102,9 +102,6 @@
|
|||||||
|
|
||||||
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 add_all_commands(parser):
|
def add_all_commands(parser):
|
||||||
"""Add all spack subcommands to the parser."""
|
"""Add all spack subcommands to the parser."""
|
||||||
@ -527,8 +524,7 @@ 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
|
spack.error.SHOW_BACKTRACE = True
|
||||||
SHOW_BACKTRACE = True
|
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
spack.util.debug.register_interrupt_handler()
|
spack.util.debug.register_interrupt_handler()
|
||||||
@ -1021,19 +1017,19 @@ 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") or SHOW_BACKTRACE:
|
if spack.config.get("config:debug") or spack.error.SHOW_BACKTRACE:
|
||||||
raise
|
raise
|
||||||
sys.stderr.write("\n")
|
sys.stderr.write("\n")
|
||||||
tty.error("Keyboard interrupt.")
|
tty.error("Keyboard interrupt.")
|
||||||
return signal.SIGINT.value
|
return signal.SIGINT.value
|
||||||
|
|
||||||
except SystemExit as e:
|
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()
|
traceback.print_exc()
|
||||||
return e.code
|
return e.code
|
||||||
|
|
||||||
except Exception as e:
|
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
|
raise
|
||||||
tty.error(e)
|
tty.error(e)
|
||||||
return 3
|
return 3
|
||||||
|
Loading…
Reference in New Issue
Block a user