From 9cc7b0945bf321e255644bcec514d841a998cdab Mon Sep 17 00:00:00 2001 From: Seth Schoen Date: Tue, 10 Feb 2015 17:51:49 -0800 Subject: [PATCH] raise ValueError instead of raw Exception --- letsencrypt/client/standalone_authenticator.py | 9 +++------ .../client/tests/standalone_authenticator_test.py | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/letsencrypt/client/standalone_authenticator.py b/letsencrypt/client/standalone_authenticator.py index a6b774e56..a1b1daa58 100755 --- a/letsencrypt/client/standalone_authenticator.py +++ b/letsencrypt/client/standalone_authenticator.py @@ -273,13 +273,11 @@ class StandaloneAuthenticator(object): if self.child_pid or self.tasks: # We should not be willing to continue with perform # if there were existing pending challenges. - # TODO: Specify a correct exception subclass. - raise Exception(".perform() was called with pending tasks!") + raise ValueError(".perform() was called with pending tasks!") results_if_success = [] results_if_failure = [] if not chall_list or not isinstance(chall_list, list): - # TODO: Specify a correct exception subclass. - raise Exception(".perform() was called without challenge list") + raise ValueError(".perform() was called without challenge list") for chall in chall_list: if isinstance(chall, challenge_util.DvsniChall): # We will attempt to do it @@ -296,8 +294,7 @@ class StandaloneAuthenticator(object): results_if_success.append(False) results_if_failure.append(False) if not self.tasks: - # TODO: Specify a correct exception subclass. - raise Exception("nothing for .perform() to do") + raise ValueError("nothing for .perform() to do") # Try to do the authentication; note that this creates # the listener subprocess via os.fork() if self.start_listener(constants.DVSNI_CHALLENGE_PORT, key): diff --git a/letsencrypt/client/tests/standalone_authenticator_test.py b/letsencrypt/client/tests/standalone_authenticator_test.py index 7bb15d5f0..0beb0b1d9 100644 --- a/letsencrypt/client/tests/standalone_authenticator_test.py +++ b/letsencrypt/client/tests/standalone_authenticator_test.py @@ -240,18 +240,18 @@ class PerformTest(unittest.TestCase): self.authenticator.tasks = {"foononce.acme.invalid": "cert_data"} extra_challenge = challenge_util.DvsniChall("a", "b", "c", "d") self.assertRaises( - Exception, self.authenticator.perform, [extra_challenge]) + ValueError, self.authenticator.perform, [extra_challenge]) def test_perform_without_challenge_list(self): extra_challenge = challenge_util.DvsniChall("a", "b", "c", "d") # This is wrong because a challenge must be specified. - self.assertRaises(Exception, self.authenticator.perform, []) + self.assertRaises(ValueError, self.authenticator.perform, []) # This is wrong because it must be a list, not a bare challenge. self.assertRaises( - Exception, self.authenticator.perform, extra_challenge) + ValueError, self.authenticator.perform, extra_challenge) # This is wrong because the list must contain at least one challenge. self.assertRaises( - Exception, self.authenticator.perform, range(20)) + ValueError, self.authenticator.perform, range(20)) class StartListenerTest(unittest.TestCase):