mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 03:41:53 +02:00
Find a better semantic for HumanException.
These are the exceptions that are likely to happen, so we give them extra, human-readable descriptions. Also, name them more in line with stdlib exceptions.
This commit is contained in:
@@ -47,7 +47,7 @@ I2OU8tPRzqKdQ6AwS9wvqscCAwEAAQ==
|
|||||||
""" # TODO: Replace with real one.
|
""" # TODO: Replace with real one.
|
||||||
|
|
||||||
|
|
||||||
class HumanException(Exception):
|
class ExpectedError(Exception):
|
||||||
"""A novice-readable exception that also carries the original exception for
|
"""A novice-readable exception that also carries the original exception for
|
||||||
debugging"""
|
debugging"""
|
||||||
|
|
||||||
@@ -66,13 +66,13 @@ class HttpsGetter(object):
|
|||||||
def get(self, url):
|
def get(self, url):
|
||||||
"""Return the document contents pointed to by an HTTPS URL.
|
"""Return the document contents pointed to by an HTTPS URL.
|
||||||
|
|
||||||
If something goes wrong (404, timeout, etc.), raise HumanException.
|
If something goes wrong (404, timeout, etc.), raise ExpectedError.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return self._opener.open(url).read()
|
return self._opener.open(url).read()
|
||||||
except (HTTPError, IOError) as exc:
|
except (HTTPError, IOError) as exc:
|
||||||
raise HumanException("Couldn't download %s." % url, exc)
|
raise ExpectedError("Couldn't download %s." % url, exc)
|
||||||
|
|
||||||
|
|
||||||
class TempDir(object):
|
class TempDir(object):
|
||||||
@@ -100,7 +100,7 @@ def verified_new_le_auto(get, tag, temp):
|
|||||||
"""Return the path to a verified, up-to-date letsencrypt-auto script.
|
"""Return the path to a verified, up-to-date letsencrypt-auto script.
|
||||||
|
|
||||||
If the download's signature does not verify or something else goes wrong,
|
If the download's signature does not verify or something else goes wrong,
|
||||||
raise HumanException.
|
raise ExpectedError.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
root = ('https://raw.githubusercontent.com/letsencrypt/letsencrypt/%s/' %
|
root = ('https://raw.githubusercontent.com/letsencrypt/letsencrypt/%s/' %
|
||||||
@@ -119,8 +119,8 @@ def verified_new_le_auto(get, tag, temp):
|
|||||||
stdout=dev_null,
|
stdout=dev_null,
|
||||||
stderr=dev_null)
|
stderr=dev_null)
|
||||||
except CalledProcessError as exc:
|
except CalledProcessError as exc:
|
||||||
raise HumanException("Couldn't verify signature of downloaded "
|
raise ExpectedError("Couldn't verify signature of downloaded "
|
||||||
"letsencrypt-auto.", exc)
|
"letsencrypt-auto.", exc)
|
||||||
else: # belt & suspenders
|
else: # belt & suspenders
|
||||||
return le_auto_path
|
return le_auto_path
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ def main():
|
|||||||
try:
|
try:
|
||||||
stable_tag = 'v' + latest_stable_version(get, 'letsencrypt')
|
stable_tag = 'v' + latest_stable_version(get, 'letsencrypt')
|
||||||
print verified_new_le_auto(get, stable_tag, temp)
|
print verified_new_le_auto(get, stable_tag, temp)
|
||||||
except HumanException as exc:
|
except ExpectedError as exc:
|
||||||
print exc.args[0], exc.args[1]
|
print exc.args[0], exc.args[1]
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user