Patchwork pwclient: catch non-existing hash gracefully

login
register
mail settings
Submitter aldot
Date Nov. 6, 2013, 11:35 p.m.
Message ID <1383780936-15677-1-git-send-email-rep.dot.nop@gmail.com>
Download mbox | patch
Permalink /patch/289072/
State Changes Requested
Headers show

Comments

aldot - Nov. 6, 2013, 11:35 p.m.
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@gmail.com>
---
 apps/patchwork/bin/pwclient |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Jeremy Kerr - Nov. 7, 2013, 12:40 a.m.
Hi Bernhard,

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

Ah, good catch.

However:

> @@ -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

I'm not sure I like the nested try blocks or the match-anything except
clauses. Could you rework this to something like this perhaps?

  patch = {}
  try:
      patch = ...
  except xmlrpclib.Fault:
      pass

  if patch == {}:
      try:
          patch = ...
      except (whatever-exception-here):
          pass

  if patch == {}
      return None



Cheers,


Jeremy

Patch

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