Skip to content

Commit

Permalink
do not show full traceback by default
Browse files Browse the repository at this point in the history
Change the behavior of the main program to show
only the summary of an exception and not the full
traceback, by default. Add a `--debug` flag to
expose the traceback information for debugging, if
needed.
  • Loading branch information
dhellmann committed Nov 1, 2024
1 parent 497073b commit 9d3e4b9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/fromager/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

TERSE_LOG_FMT = "%(message)s"
VERBOSE_LOG_FMT = "%(levelname)s:%(name)s:%(lineno)d: %(message)s"
_DEBUG = False

try:
external_commands.detect_network_isolation()
Expand All @@ -37,6 +38,12 @@
is_flag=True,
help="report more detail to the console",
)
@click.option(
"--debug",
default=False,
is_flag=True,
help="report full tracebacks to the console",
)
@click.option(
"--log-file",
type=clickext.ClickPath(),
Expand Down Expand Up @@ -131,6 +138,7 @@
def main(
ctx: click.Context,
verbose: bool,
debug: bool,
log_file: pathlib.Path,
error_log_file: pathlib.Path,
sdists_repo: pathlib.Path,
Expand All @@ -146,6 +154,10 @@ def main(
jobs: int | None,
network_isolation: bool,
) -> None:
# Save the debug flag so invoke_main() can use it.
global _DEBUG
_DEBUG = debug

# Set the overall logger level to debug and allow the handlers to filter
# messages at their own level.
logging.getLogger().setLevel(logging.DEBUG)
Expand Down Expand Up @@ -226,8 +238,13 @@ def invoke_main() -> None:
try:
main(auto_envvar_prefix="FROMAGER")
except Exception as err:
logger.exception(err)
raise
logger.debug(
err,
exc_info=True,
) # log the full traceback details to the debug log file, if any
logger.error(f"ERROR: {err}")
if _DEBUG:
raise


if __name__ == "__main__":
Expand Down

0 comments on commit 9d3e4b9

Please sign in to comment.