[PATCH] dispatch: factor out command failure handling into a function

Yuya Nishihara yuya at tcha.org
Fri Mar 25 11:04:44 EDT 2016


On Wed, 23 Mar 2016 16:40:33 -0700, Martijn Pieters wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpieters at fb.com>
> # Date 1458775506 25200
> #      Wed Mar 23 16:25:06 2016 -0700
> # Node ID d45ba07deb133f30c7188d7e6f671535558c8f83
> # Parent  35c2f607a1ebc57bac43e0c658168d2a7b631f87
> dispatch: factor out command failure handling into a function
> 
> Moving the warning generation and re-raise to a function allows for wrapping
> and alternative error handling.
> 
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -332,60 +332,7 @@
>      except socket.error as inst:
>          ui.warn(_("abort: %s\n") % inst.args[-1])
>      except: # re-raises

[...]

> -        ui.log("commandexception", "%s\n%s\n", warning, traceback.format_exc())
> -        ui.warn(warning)
> -        raise
> +        handlecommandexception(ui)

Moving re-"raise" statement would make the exception path unclear. Can it be
kept in the "except" clause? For example,

  except: # re-raises
      if not _handleunknownexception(ui):
          raise


More information about the Mercurial-devel mailing list