From 068988085ea0a1aa00dadd96df7f1e8d1ce8c1ee Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 8 Feb 2017 00:39:47 +0300 Subject: [PATCH] upip: Report package not found and similar errors with less noise. While still allow to get full backtrace with --debug. --- upip/upip.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/upip/upip.py b/upip/upip.py index db18a742..93644d59 100644 --- a/upip/upip.py +++ b/upip/upip.py @@ -124,13 +124,14 @@ def url_open(url): l = s.readline() protover, status, msg = l.split(None, 2) if status != b"200": + exc = ValueError(status) if status == b"404": - print("Package not found") - raise ValueError(status) + fatal("Package not found", exc) + fatal("Unexpected error querying for package", exc) while 1: l = s.readline() if not l: - raise ValueError("Unexpected EOF") + fatal("Unexpected EOF in HTTP headers", ValueError()) if l == b'\r\n': break @@ -144,8 +145,10 @@ def get_pkg_metadata(name): return json.loads(s) -def fatal(msg): - print(msg) +def fatal(msg, exc=None): + print("Error:", msg) + if exc and debug: + raise exc sys.exit(1) def install_pkg(pkg_spec, install_path):