Skip to content

Commit

Permalink
format chained exceptions to include all of the messages
Browse files Browse the repository at this point in the history
When we get an exception chain with more than one
member, include the messages from all of them.
  • Loading branch information
dhellmann committed Nov 7, 2024
1 parent a3fa2a5 commit 6f55040
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/fromager/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit 6f55040

Please sign in to comment.