mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 08:45:19 +02:00
log: Don't print backtrace on ^c/KeyboardInterrupt (#8259)
This commit is contained in:
@@ -319,6 +319,9 @@ def post_arg_parse_except_hook(exc_type, exc_value, trace, debug, log_path):
|
||||
# logger.DEBUG should be used
|
||||
if debug or not issubclass(exc_type, Exception):
|
||||
assert constants.QUIET_LOGGING_LEVEL <= logging.ERROR
|
||||
if exc_type is KeyboardInterrupt:
|
||||
logger.error('Exiting due to user request.')
|
||||
sys.exit(1)
|
||||
logger.error('Exiting abnormally:', exc_info=exc_info)
|
||||
else:
|
||||
logger.debug('Exiting abnormally:', exc_info=exc_info)
|
||||
|
||||
@@ -306,7 +306,7 @@ class PostArgParseExceptHookTest(unittest.TestCase):
|
||||
self.log_path = 'foo.log'
|
||||
|
||||
def test_base_exception(self):
|
||||
exc_type = KeyboardInterrupt
|
||||
exc_type = BaseException
|
||||
mock_logger, output = self._test_common(exc_type, debug=False)
|
||||
self._assert_exception_logged(mock_logger.error, exc_type)
|
||||
self._assert_logfile_output(output)
|
||||
@@ -342,6 +342,11 @@ class PostArgParseExceptHookTest(unittest.TestCase):
|
||||
self._assert_exception_logged(mock_logger.debug, exc_type)
|
||||
self._assert_quiet_output(mock_logger, output)
|
||||
|
||||
def test_keyboardinterrupt(self):
|
||||
exc_type = KeyboardInterrupt
|
||||
mock_logger, output = self._test_common(exc_type, debug=False)
|
||||
mock_logger.error.assert_called_once_with('Exiting due to user request.')
|
||||
|
||||
def _test_common(self, error_type, debug):
|
||||
"""Returns the mocked logger and stderr output."""
|
||||
mock_err = six.StringIO()
|
||||
|
||||
Reference in New Issue
Block a user