[PATCH] dispatch: split global error handling out so it can be reused
Yuya Nishihara
yuya at tcha.org
Wed Aug 10 08:01:25 EDT 2016
On Tue, 9 Aug 2016 16:46:57 +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1470757528 -3600
> # Tue Aug 09 16:45:28 2016 +0100
> # Node ID b43232adc0f8f60285921bdb65fd0f55710ed3b2
> # Parent 3dbc95f3eb31874ab4633f936acff4609714dc41
> # Available At https://bitbucket.org/quark-zju/hg-draft
> # hg pull https://bitbucket.org/quark-zju/hg-draft -r b43232adc0f8
> dispatch: split global error handling out so it can be reused
>
> We may want a similar error handling at worker.py. This patch extracts the
> error handling logic to "callcatch" so it can be reused.
>
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -150,7 +150,7 @@ def _runcatch(req):
> except ValueError:
> pass # happens if called in a thread
>
> - try:
> + def _runcatchfunc():
> try:
> debugger = 'pdb'
> debugtrace = {
> @@ -212,6 +212,16 @@ def _runcatch(req):
> ui.traceback()
> raise
>
> + return callcatch(ui, _runcatchfunc)
> +
> +def callcatch(ui, func):
> + """call func() with global exception handling
> +
> + return func() if no exception happens. otherwise do some error handling
> + and return an exit code accordingly.
> + """
> + try:
> + return func()
The code and docstring look good, but did you try using this function?
I suspect it would create an import cycle.
More information about the Mercurial-devel
mailing list