[PATCH] pwclient: catch non-existing hash gracefully

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Thu Nov 7 10:35:36 EST 2013


I was calling view -h deadbeef on the wrong project, silence that and
additionally prevent the same thing if the fallback fails.

Traceback (most recent call last):
  File "/home/me/bin/pwclient", line 500, in <module>
    main()
  File "/home/me/bin/pwclient", line 427, in main
    patch_id = patch_id_from_hash(rpc, project_str, hash_str)
  File "/home/me/bin/pwclient", line 317, in patch_id_from_hash
    patch = rpc.patch_get_by_project_hash(project, hash)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1297, in single_request
    return self.parse_response(response)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1471, in parse_response
    p.close()
  File "/usr/lib/python2.7/xmlrpclib.py", line 560, in close
    self._parser.Parse("", 1) # end of data
xml.parsers.expat.ExpatError: no element found: line 1, column 0

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 apps/patchwork/bin/pwclient |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/apps/patchwork/bin/pwclient b/apps/patchwork/bin/pwclient
index 5fce359..62b7553 100755
--- a/apps/patchwork/bin/pwclient
+++ b/apps/patchwork/bin/pwclient
@@ -313,12 +313,16 @@ def action_update_patch(rpc, patch_id, state = None, commit = None):
         sys.stderr.write("Patch not updated\n")
 
 def patch_id_from_hash(rpc, project, hash):
+    patch = {}
     try:
         patch = rpc.patch_get_by_project_hash(project, hash)
     except xmlrpclib.Fault:
         # the server may not have the newer patch_get_by_project_hash function,
         # so fall back to hash-only.
-        patch = rpc.patch_get_by_hash(hash)
+        try:
+            patch = rpc.patch_get_by_hash(hash)
+        except: pass
+    except: pass
 
     if patch == {}:
         return None
-- 
1.7.10.4



More information about the Patchwork mailing list