[PATCH 1 of 2] dispatch: fix exit code of unhandled exception recorded in blackbox log

Yuya Nishihara yuya at tcha.org
Wed May 16 12:19:37 UTC 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1526469470 -32400
#      Wed May 16 20:17:50 2018 +0900
# Node ID d5956b687bbc39c686390b45d08caea976b8b7dd
# Parent  81ca0fd348e3fe3bd442b2eb0d1232abef069155
dispatch: fix exit code of unhandled exception recorded in blackbox log

Spotted by Martin von Zweigbergk.

We might want to change the exit code to -1 (i.e. 255) because 1 means
non-abort error in hg, but that's another issue.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -208,7 +208,7 @@ def dispatch(req):
 
     msg = _formatargs(req.args)
     starttime = util.timer()
-    ret = -1
+    ret = 1  # default of Python exit code on unhandled exception
     try:
         ret = _runcatch(req) or 0
     except error.ProgrammingError as inst:
@@ -239,7 +239,7 @@ def dispatch(req):
             req.ui.log('uiblocked', 'ui blocked ms',
                        **pycompat.strkwargs(req.ui._blockedtimes))
         req.ui.log("commandfinish", "%s exited %d after %0.2f seconds\n",
-                   msg, ret or 0, duration)
+                   msg, ret, duration)
         try:
             req._runexithandlers()
         except: # exiting, so no re-raises
diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t
--- a/tests/test-blackbox.t
+++ b/tests/test-blackbox.t
@@ -49,7 +49,7 @@ unhandled exception
   $ hg crash 2> /dev/null
   [1]
   $ hg blackbox -l 2
-  1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> crash exited -1 after * seconds (glob)
+  1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> crash exited 1 after * seconds (glob)
   1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> blackbox -l 2
 
 alias expansion is logged


More information about the Mercurial-devel mailing list