From 5ec29ca60bc48938fadc02ab4bcd89db0891d7f8 Mon Sep 17 00:00:00 2001 From: alexzorin Date: Fri, 25 Sep 2020 07:22:38 +1000 Subject: [PATCH] suppress tracebacks in ErrorHandler recovery (#8310) The ErrorHandler context manager could produce very verbose CLI output when handling long exception chains (PIP 3134 enhanced reporting). Rather than logging every exception with its traceback to the CLI, this commit changes ErrorHandler so that only the final exception in the chain, without traceback, is logged to the CLI. This is consistent with a previous change made in the global except hook (#8000). --- certbot/CHANGELOG.md | 1 + certbot/certbot/_internal/error_handler.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/certbot/CHANGELOG.md b/certbot/CHANGELOG.md index d4b7ac21b..0ff09b5e2 100644 --- a/certbot/CHANGELOG.md +++ b/certbot/CHANGELOG.md @@ -14,6 +14,7 @@ Certbot adheres to [Semantic Versioning](https://semver.org/). * Update the packaging instructions to promote usage of `python -m pytest` to test Certbot instead of the deprecated `python setup.py test` setuptools approach. * Reduced CLI logging when reloading nginx, if it is not running. +* Reduced CLI logging when handling some kinds of errors. ### Fixed diff --git a/certbot/certbot/_internal/error_handler.py b/certbot/certbot/_internal/error_handler.py index 41c12eafa..60fb287a6 100644 --- a/certbot/certbot/_internal/error_handler.py +++ b/certbot/certbot/_internal/error_handler.py @@ -123,8 +123,10 @@ class ErrorHandler(object): while self.funcs: try: self.funcs[-1]() - except Exception: # pylint: disable=broad-except - logger.error("Encountered exception during recovery: ", exc_info=True) + except Exception as exc: # pylint: disable=broad-except + output = traceback.format_exception_only(type(exc), exc) + logger.error("Encountered exception during recovery: %s", + ''.join(output).rstrip()) self.funcs.pop() def _set_signal_handlers(self):