From 6f55040f3019809199b39f3c19b362a89f16418f Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 7 Nov 2024 15:35:12 -0500 Subject: [PATCH] format chained exceptions to include all of the messages When we get an exception chain with more than one member, include the messages from all of them. --- src/fromager/__main__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fromager/__main__.py b/src/fromager/__main__.py index e4afffd9..2363fdbc 100644 --- a/src/fromager/__main__.py +++ b/src/fromager/__main__.py @@ -238,6 +238,13 @@ def main( main.add_command(cmd) +def _format_exception(exc): + if exc.__cause__: + cause = _format_exception(exc.__cause__) + return f"{exc} because {cause}" + return str(exc) + + def invoke_main() -> None: # Wrapper for the click main command that ensures any exceptions # are logged so that build pipeline outputs include the traceback. @@ -248,7 +255,7 @@ def invoke_main() -> None: err, exc_info=True, ) # log the full traceback details to the debug log file, if any - logger.error(f"ERROR: {err}") + logger.error(f"ERROR: {_format_exception(err)}") if _DEBUG: raise sys.exit(1)