From 7cd47eb73aa2527d0c1c930a34f50908223b30f0 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Tue, 8 Mar 2016 00:28:41 +0100 Subject: [PATCH] Ensure that a download failure is properly raised before the read fails Without this change, a download failure may bail out with the message: "Failure downloading http://foo/bar, 'NoneType' object has no attribute 'read'" whereas with this fix, you'd get a proper error like: "Failure downloading http://foo/bar, Request failed: " or one of the many other possible download errors that can occur. --- files/unarchive.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/files/unarchive.py b/files/unarchive.py index 251fbab35e8..e4bb230aef5 100644 --- a/files/unarchive.py +++ b/files/unarchive.py @@ -282,6 +282,9 @@ def main(): package = os.path.join(tempdir, str(src.rsplit('/', 1)[1])) try: rsp, info = fetch_url(module, src) + # If download fails, raise a proper exception + if rsp is None: + raise Exception(info['msg']) f = open(package, 'w') # Read 1kb at a time to save on ram while True: