[PATCH] pwclient: catch non-existing hash gracefully

Jeremy Kerr jk at ozlabs.org
Thu Nov 7 11:40:18 EST 2013


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


More information about the Patchwork mailing list