Fix AttributeError on HTTPError in deploy code 23/15123/2
authorThanh Ha <thanh.ha@linuxfoundation.org>
Fri, 29 Mar 2019 15:21:23 +0000 (11:21 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Fri, 29 Mar 2019 15:27:31 +0000 (11:27 -0400)
When a deploy nexus-zip fails it throws a stack trace with:

    AttributeError: 'HTTPError' object has no attribute 'value'

Which is a very unhelpful error message but it's caused by the
error handler code incorrectly handling the returned string value
for the exception.

Change-Id: I6d059dd73a5e774c15ab90a3b53728d6e051bf0c
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
lftools/deploy.py
releasenotes/notes/fix-httperror-exception-6017608b5f939733.yaml [new file with mode: 0644]

index 51bba1b..094119a 100644 (file)
@@ -359,7 +359,7 @@ def deploy_nexus_zip(nexus_url, nexus_repo, nexus_path, zip_file):
         log.info("Uploading {} failed. It contained the following files".format(zip_file))
         for f in files:
             log.info("   {}".format(f))
-        raise requests.HTTPError(e.value)
+        raise requests.HTTPError(e)
     log.debug('{}: {}'.format(resp.status_code, resp.text))
 
 
diff --git a/releasenotes/notes/fix-httperror-exception-6017608b5f939733.yaml b/releasenotes/notes/fix-httperror-exception-6017608b5f939733.yaml
new file mode 100644 (file)
index 0000000..b819fc1
--- /dev/null
@@ -0,0 +1,40 @@
+---
+fixes:
+  - |
+    Fix the unhelpful stack trace when a deploy nexus-zip fails to upload.
+
+    .. code-block:: bash
+
+        Traceback (most recent call last):
+          File "/home/jenkins/.local/bin/lftools", line 10, in <module>
+            sys.exit(main())
+          File "/home/jenkins/.local/lib/python2.7/site-packages/lftools/cli/__init__.py", line 110, in main
+            cli(obj={})
+          File "/usr/lib/python2.7/site-packages/click/core.py", line 721, in __call__
+            return self.main(*args, **kwargs)
+          File "/usr/lib/python2.7/site-packages/click/core.py", line 696, in main
+            rv = self.invoke(ctx)
+          File "/usr/lib/python2.7/site-packages/click/core.py", line 1065, in invoke
+            return _process_result(sub_ctx.command.invoke(sub_ctx))
+          File "/usr/lib/python2.7/site-packages/click/core.py", line 1065, in invoke
+            return _process_result(sub_ctx.command.invoke(sub_ctx))
+          File "/usr/lib/python2.7/site-packages/click/core.py", line 894, in invoke
+            return ctx.invoke(self.callback, **ctx.params)
+          File "/usr/lib/python2.7/site-packages/click/core.py", line 534, in invoke
+            return callback(*args, **kwargs)
+          File "/usr/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
+            return f(get_current_context(), *args, **kwargs)
+          File "/home/jenkins/.local/lib/python2.7/site-packages/lftools/cli/deploy.py", line 63, in archives
+            deploy_sys.deploy_archives(nexus_url, nexus_path, workspace, pattern)
+          File "/home/jenkins/.local/lib/python2.7/site-packages/lftools/deploy.py", line 236, in deploy_archives
+            deploy_nexus_zip(nexus_url, 'logs', nexus_path, archives_zip)
+          File "/home/jenkins/.local/lib/python2.7/site-packages/lftools/deploy.py", line 362, in deploy_nexus_zip
+            raise requests.HTTPError(e.value)
+        AttributeError: 'HTTPError' object has no attribute 'value'
+
+
+    Now instead it returns a much more helpful error message::
+
+        ERROR: Failed to upload to Nexus with status code: 401.
+
+        test.zip