Skip to content

Commit aac2db9

Browse files
committed
tools/upip: Update to 1.1.5. Better and more user-friendly error handling.
1 parent e08395a commit aac2db9

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tools/upip.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ def expandhome(s):
105105
def url_open(url):
106106
global warn_ussl
107107
proto, _, host, urlpath = url.split('/', 3)
108-
ai = usocket.getaddrinfo(host, 443)
108+
try:
109+
ai = usocket.getaddrinfo(host, 443)
110+
except OSError as e:
111+
fatal("Unable to resolve %s (no Internet?)" % host, e)
109112
#print("Address infos:", ai)
110113
addr = ai[0][4]
111114

@@ -124,13 +127,16 @@ def url_open(url):
124127
l = s.readline()
125128
protover, status, msg = l.split(None, 2)
126129
if status != b"200":
130+
s.close()
131+
exc = ValueError(status)
127132
if status == b"404":
128-
print("Package not found")
129-
raise ValueError(status)
133+
fatal("Package not found", exc)
134+
fatal("Unexpected error querying for package", exc)
130135
while 1:
131136
l = s.readline()
132137
if not l:
133-
raise ValueError("Unexpected EOF")
138+
s.close()
139+
fatal("Unexpected EOF in HTTP headers", ValueError())
134140
if l == b'\r\n':
135141
break
136142

@@ -144,8 +150,10 @@ def get_pkg_metadata(name):
144150
return json.loads(s)
145151

146152

147-
def fatal(msg):
148-
print(msg)
153+
def fatal(msg, exc=None):
154+
print("Error:", msg)
155+
if exc and debug:
156+
raise exc
149157
sys.exit(1)
150158

151159
def install_pkg(pkg_spec, install_path):

0 commit comments

Comments
 (0)