# HG changeset patch # User Jun Wu # Date 2016-08-09 15:45:28 # Node ID 39149b6036e6d08082907f174443f9cff18f988d # Parent 3df9f780c90ec179a2f87802f352a0273da9a364 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() # Global exception handling, alphabetically # Mercurial-specific first, followed by built-in and library exceptions except error.AmbiguousCommand as inst: diff --git a/tests/test-devel-warnings.t b/tests/test-devel-warnings.t --- a/tests/test-devel-warnings.t +++ b/tests/test-devel-warnings.t @@ -91,6 +91,8 @@ */mercurial/dispatch.py:* in run (glob) */mercurial/dispatch.py:* in dispatch (glob) */mercurial/dispatch.py:* in _runcatch (glob) + */mercurial/dispatch.py:* in callcatch (glob) + */mercurial/dispatch.py:* in _runcatchfunc (glob) */mercurial/dispatch.py:* in _dispatch (glob) */mercurial/dispatch.py:* in runcommand (glob) */mercurial/dispatch.py:* in _runcommand (glob) @@ -125,6 +127,8 @@ */mercurial/dispatch.py:* in run (glob) */mercurial/dispatch.py:* in dispatch (glob) */mercurial/dispatch.py:* in _runcatch (glob) + */mercurial/dispatch.py:* in callcatch (glob) + */mercurial/dispatch.py:* in _runcatchfunc (glob) */mercurial/dispatch.py:* in _dispatch (glob) */mercurial/dispatch.py:* in runcommand (glob) */mercurial/dispatch.py:* in _runcommand (glob) @@ -147,6 +151,8 @@ */mercurial/dispatch.py:* in run (glob) */mercurial/dispatch.py:* in dispatch (glob) */mercurial/dispatch.py:* in _runcatch (glob) + */mercurial/dispatch.py:* in callcatch (glob) + */mercurial/dispatch.py:* in _runcatchfunc (glob) */mercurial/dispatch.py:* in _dispatch (glob) */mercurial/dispatch.py:* in runcommand (glob) */mercurial/dispatch.py:* in _runcommand (glob)