[PATCH] dispatch: split global error handling out so it can be reused

Jun Wu quark at fb.com
Tue Aug 9 15:46:57 UTC 2016


# 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()
     # Global exception handling, alphabetically
     # Mercurial-specific first, followed by built-in and library exceptions
     except error.AmbiguousCommand as inst:


More information about the Mercurial-devel mailing list