]> scripts.mit.edu Git - wizard.git/commitdiff
Replace gaierror with more user-friendly message.
authorEdward Z. Yang <ezyang@mit.edu>
Wed, 3 Mar 2010 05:14:07 +0000 (00:14 -0500)
committerEdward Z. Yang <ezyang@mit.edu>
Wed, 3 Mar 2010 05:14:07 +0000 (00:14 -0500)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
TODO
wizard/util.py

diff --git a/TODO b/TODO
index ffeda79d2cddb4b3380e94cc66d5cb6ca4e3dd75..523f3013ff21f992d8c80a60b77b24c14e6fc37c 100644 (file)
--- a/TODO
+++ b/TODO
@@ -22,8 +22,6 @@ TODO NOW:
 - Parse output HTML for class="error" and give those errors back to the user (done),
   then boot them back into configure so they can enter in something different
 
-- Replace gaierror with a more descriptive name (this is a DNS error)
-
 - Pre-emptively check if daemon/scripts-security-upd
   is not on scripts-security-upd list (/mit/moira/bin/blanche)
 - If you try to do an install on scripts w/o sql, it will sign you up but fail to write
index a6e8f243dabf48a8792b442f51e75183ef4698c9..1c884035af4e04562488301e75d164fa6cd9e848 100644 (file)
@@ -344,17 +344,25 @@ def soft_unlink(file):
         pass
 
 def fetch(host, path, subpath, post=None):
-    h = httplib.HTTPConnection(host)
-    fullpath = path.rstrip("/") + "/" + subpath.lstrip("/") # to be lenient about input we accept
-    if post:
-        headers = {"Content-type": "application/x-www-form-urlencoded"}
-        h.request("POST", fullpath, urllib.urlencode(post), headers)
-    else:
-        h.request("GET", fullpath)
-    r = h.getresponse()
-    data = r.read()
-    h.close()
-    return data
+    try:
+        # XXX: Special case if it's https; not sure why this data isn't
+        # passed
+        h = httplib.HTTPConnection(host)
+        fullpath = path.rstrip("/") + "/" + subpath.lstrip("/") # to be lenient about input we accept
+        if post:
+            headers = {"Content-type": "application/x-www-form-urlencoded"}
+            h.request("POST", fullpath, urllib.urlencode(post), headers)
+        else:
+            h.request("GET", fullpath)
+        r = h.getresponse()
+        data = r.read()
+        h.close()
+        return data
+    except socket.gaierror as e:
+        if e.errno == socket.EAI_NONAME:
+            raise DNSError(host)
+        else:
+            raise
 
 def mixed_newlines(filename):
     """Returns ``True`` if ``filename`` has mixed newlines."""
@@ -384,3 +392,14 @@ ERROR: Could not acquire lock on directory.  Maybe there is
 another migration process running?
 """
 
+class DNSError(socket.gaierror):
+    errno = socket.EAI_NONAME
+    #: Hostname that could not resolve name
+    host = None
+    def __init__(self, host):
+        self.host = host
+    def __str__(self):
+        return """
+
+ERROR: Could not resolve hostname %s.
+""" % self.host