From 22e0f5779abe811e0f44c0a8d79b49b387e3dfdc Mon Sep 17 00:00:00 2001 From: Peter Eckersley Date: Fri, 9 Dec 2016 14:56:14 -0800 Subject: [PATCH] Fix --debug (#3877) * Fix the --debug flag - Currently exceptions are often caught and burried in log files, even if this flag is provided! * Explain the insanity * Make things slightly nicer --- certbot/main.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/certbot/main.py b/certbot/main.py index 395790faa..2baab9670 100644 --- a/certbot/main.py +++ b/certbot/main.py @@ -702,10 +702,8 @@ def _handle_exception(exc_type, exc_value, trace, config): to the user. sys.exit is always called with a nonzero status. """ - logger.debug( - "Exiting abnormally:%s%s", - os.linesep, - "".join(traceback.format_exception(exc_type, exc_value, trace))) + tb_str = "".join(traceback.format_exception(exc_type, exc_value, trace)) + logger.debug("Exiting abnormally:%s%s", os.linesep, tb_str) if issubclass(exc_type, Exception) and (config is None or not config.debug): if config is None: @@ -715,8 +713,9 @@ def _handle_exception(exc_type, exc_value, trace, config): traceback.print_exception( exc_type, exc_value, trace, file=logfd) except: # pylint: disable=bare-except - sys.exit("".join( - traceback.format_exception(exc_type, exc_value, trace))) + sys.exit(tb_str) + if "--debug" in sys.argv: + sys.exit(tb_str) if issubclass(exc_type, errors.Error): sys.exit(exc_value) @@ -741,8 +740,7 @@ def _handle_exception(exc_type, exc_value, trace, config): msg += "logfiles in {0} for more details.".format(config.logs_dir) sys.exit(msg) else: - sys.exit("".join( - traceback.format_exception(exc_type, exc_value, trace))) + sys.exit(tb_str) def make_or_verify_core_dir(directory, mode, uid, strict):