From b8ecccbde9d3598de0bf31ef5a40e1c036680f93 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 15 Aug 2024 00:00:39 -0700 Subject: [PATCH] installer: show tracebacks from builds to debug failed installs `installer.py` currently swallows the traceback and preserves only the error messaege if a build process fails. - [x] preserve exceptions from failed build processes - [x] print a full traceback for each one when running with `spack -d` Signed-off-by: Todd Gamblin --- lib/spack/spack/installer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/installer.py b/lib/spack/spack/installer.py index 80fe9f2b038..fe071691da6 100644 --- a/lib/spack/spack/installer.py +++ b/lib/spack/spack/installer.py @@ -36,6 +36,7 @@ import shutil import sys import time +import traceback from collections import defaultdict from gzip import GzipFile from typing import Dict, Iterator, List, Optional, Set, Tuple, Union @@ -2214,7 +2215,7 @@ def install(self) -> None: if task.is_build_request: if single_requested_spec: raise - failed_build_requests.append((pkg, pkg_id, str(exc))) + failed_build_requests.append((pkg, pkg_id, exc)) finally: # Remove the install prefix if anything went wrong during @@ -2241,6 +2242,9 @@ def install(self) -> None: if failed_build_requests or missing: for _, pkg_id, err in failed_build_requests: tty.error(f"{pkg_id}: {err}") + if spack.error.debug: + # note: in python 3.10+ this can just be print_exception(err) + traceback.print_exception(type(err), err, err.__traceback__) for _, pkg_id in missing: tty.error(f"{pkg_id}: Package was not installed")