Skip to content

Commit

Permalink
Merge pull request #490 from dhellmann/improve-error-formatting
Browse files Browse the repository at this point in the history
do not show full traceback by default
  • Loading branch information
mergify[bot] authored Nov 4, 2024
2 parents e76a5bf + 14c4f91 commit e58a8ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 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
5 changes: 4 additions & 1 deletion src/fromager/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def resolve_from_provider(
) -> tuple[str, Version]:
reporter: resolvelib.BaseReporter = resolvelib.BaseReporter()
rslvr: resolvelib.Resolver = resolvelib.Resolver(provider, reporter)
result = rslvr.resolve([req])
try:
result = rslvr.resolve([req])
except resolvelib.resolvers.exceptions.ResolutionImpossible as err:
raise ValueError(f"Unable to resolve {req}") from err
# resolvelib actually just returns one candidate per requirement.
# result.mapping is map from an identifier to its resolved candidate
candidate: Candidate
Expand Down

0 comments on commit e58a8ea

Please sign in to comment.