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().
This commit is contained in:
Brad Warren
2017-06-01 10:42:34 -07:00
committed by GitHub
parent 791fea43ec
commit 738732a0db
2 changed files with 5 additions and 2 deletions
+1 -1
View File
@@ -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)
+4 -1
View File
@@ -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())