diff mercurial/dispatch.py @ 29761:39149b6036e6

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.
author Jun Wu <quark@fb.com>
date Tue, 09 Aug 2016 16:45:28 +0100
parents 12769703d4ba
children 2654a0aac80d
line wrap: on
line diff
--- a/mercurial/dispatch.py	Wed Aug 10 04:35:44 2016 +0530
+++ b/mercurial/dispatch.py	Tue Aug 09 16:45:28 2016 +0100
@@ -150,7 +150,7 @@
     except ValueError:
         pass # happens if called in a thread
 
-    try:
+    def _runcatchfunc():
         try:
             debugger = 'pdb'
             debugtrace = {
@@ -212,6 +212,16 @@
             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: