From 738732a0db3f9afb916cb202ccf57d463a1cde01 Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Thu, 1 Jun 2017 10:42:34 -0700 Subject: [PATCH] Improve bad preferred challenge error message. (#4761) Using ArgumentTypeError causes Certbot to report an unexpected error occurred while using ArgumentError causes argparse to print more usage information and call sys.exit(). --- certbot/cli.py | 2 +- certbot/tests/cli_test.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/certbot/cli.py b/certbot/cli.py index 45ee78103..1023d9aca 100644 --- a/certbot/cli.py +++ b/certbot/cli.py @@ -1303,7 +1303,7 @@ class _PrefChallAction(argparse.Action): try: challs = parse_preferred_challenges(pref_challs.split(",")) except errors.Error as error: - raise argparse.ArgumentTypeError(str(error)) + raise argparse.ArgumentError(self, str(error)) namespace.pref_challs.extend(challs) diff --git a/certbot/tests/cli_test.py b/certbot/tests/cli_test.py index d29f7c1b6..f18da240a 100644 --- a/certbot/tests/cli_test.py +++ b/certbot/tests/cli_test.py @@ -211,7 +211,10 @@ class ParseTest(unittest.TestCase): self.assertEqual(namespace.pref_challs, expected) short_args = ['--preferred-challenges', 'jumping-over-the-moon'] - self.assertRaises(argparse.ArgumentTypeError, self.parse, short_args) + # argparse.ArgumentError makes argparse print more information + # to stderr and call sys.exit() + with mock.patch('sys.stderr'): + self.assertRaises(SystemExit, self.parse, short_args) def test_server_flag(self): namespace = self.parse('--server example.com'.split())