From d230dcafebf1ade14bc5f9bf5954282df42fca71 Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Mon, 18 May 2020 09:31:15 -0700 Subject: [PATCH 1/2] Print cause of exit in red text. --- certbot/certbot/_internal/log.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/certbot/certbot/_internal/log.py b/certbot/certbot/_internal/log.py index 0a492ba55..21996548d 100644 --- a/certbot/certbot/_internal/log.py +++ b/certbot/certbot/_internal/log.py @@ -323,7 +323,10 @@ def post_arg_parse_except_hook(exc_type, exc_value, trace, debug, log_path): else: logger.debug('Exiting abnormally:', exc_info=exc_info) if issubclass(exc_type, errors.Error): - sys.exit(exc_value) + # Use logger to print the error message to take advantage of + # our logger printing warnings and errors in red text. + logger.error(exc_value) + sys.exit(1) logger.error('An unexpected error occurred:') if messages.is_acme_error(exc_value): # Remove the ACME error prefix from the exception From 0e59c6ba1baf2c32f229a9b8c68fd457ba136617 Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Mon, 18 May 2020 10:17:32 -0700 Subject: [PATCH 2/2] handle more cases --- certbot/certbot/_internal/log.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/certbot/certbot/_internal/log.py b/certbot/certbot/_internal/log.py index 21996548d..3b87f9bca 100644 --- a/certbot/certbot/_internal/log.py +++ b/certbot/certbot/_internal/log.py @@ -322,10 +322,10 @@ def post_arg_parse_except_hook(exc_type, exc_value, trace, debug, log_path): logger.error('Exiting abnormally:', exc_info=exc_info) else: logger.debug('Exiting abnormally:', exc_info=exc_info) + # Use logger to print the error message to take advantage of + # our logger printing warnings and errors in red text. if issubclass(exc_type, errors.Error): - # Use logger to print the error message to take advantage of - # our logger printing warnings and errors in red text. - logger.error(exc_value) + logger.error(str(exc_value)) sys.exit(1) logger.error('An unexpected error occurred:') if messages.is_acme_error(exc_value): @@ -333,7 +333,12 @@ def post_arg_parse_except_hook(exc_type, exc_value, trace, debug, log_path): _, _, exc_str = str(exc_value).partition(':: ') logger.error(exc_str) else: - traceback.print_exception(exc_type, exc_value, None) + output = traceback.format_exception_only(exc_type, exc_value) + # format_exception_only returns a list of strings each + # terminated by a newline. We combine them into one string + # and remove the final newline before passing it to + # logger.error. + logger.error(''.join(output).rstrip()) exit_with_log_path(log_path)