Skip to content

Commit 0689880

Browse files
committed
upip: Report package not found and similar errors with less noise.
While still allow to get full backtrace with --debug.
1 parent f6668aa commit 0689880

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

upip/upip.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,14 @@ def url_open(url):
124124
l = s.readline()
125125
protover, status, msg = l.split(None, 2)
126126
if status != b"200":
127+
exc = ValueError(status)
127128
if status == b"404":
128-
print("Package not found")
129-
raise ValueError(status)
129+
fatal("Package not found", exc)
130+
fatal("Unexpected error querying for package", exc)
130131
while 1:
131132
l = s.readline()
132133
if not l:
133-
raise ValueError("Unexpected EOF")
134+
fatal("Unexpected EOF in HTTP headers", ValueError())
134135
if l == b'\r\n':
135136
break
136137

@@ -144,8 +145,10 @@ def get_pkg_metadata(name):
144145
return json.loads(s)
145146

146147

147-
def fatal(msg):
148-
print(msg)
148+
def fatal(msg, exc=None):
149+
print("Error:", msg)
150+
if exc and debug:
151+
raise exc
149152
sys.exit(1)
150153

151154
def install_pkg(pkg_spec, install_path):

0 commit comments

Comments
 (0)