error: use detailed exit code 10 for command errors
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 14 Jan 2021 11:53:55 -0800
changeset 46262 9c9e0b4b2ca7
parent 46261 c9b2a4d69e66
child 46263 d46646ce3158
error: use detailed exit code 10 for command errors Command errors (unknown or ambiguous commands, or bad command arguments or options) are handled in the `dispatch` module. Most other errors are handled in the `scmutil` module. This patch therefore has to duplicate a little bit of code from the `scmutil` module. It's just a few lines, however, so it seems fine to me. It's a pretty common category of errors, so it's important to have them respect `ui.detailed-exit-code`. Differential Revision: https://phab.mercurial-scm.org/D9777
mercurial/dispatch.py
tests/test-alias.t
tests/test-basic.t
tests/test-completion.t
tests/test-dispatch.t
tests/test-extension.t
tests/test-fastannotate.t
tests/test-help.t
tests/test-narrow-trackedcmd.t
tests/test-qrecord.t
tests/test-share-safe.t
tests/test-status-color.t
tests/test-strict.t
tests/test-strip.t
--- a/mercurial/dispatch.py	Wed Jan 13 22:37:21 2021 -0800
+++ b/mercurial/dispatch.py	Thu Jan 14 11:53:55 2021 -0800
@@ -470,14 +470,17 @@
     config parsing and commands. besides, use handlecommandexception to handle
     uncaught exceptions.
     """
+    detailed_exit_code = -1
     try:
         return scmutil.callcatch(ui, func)
     except error.AmbiguousCommand as inst:
+        detailed_exit_code = 10
         ui.warn(
             _(b"hg: command '%s' is ambiguous:\n    %s\n")
             % (inst.prefix, b" ".join(inst.matches))
         )
     except error.CommandError as inst:
+        detailed_exit_code = 10
         if inst.command:
             ui.pager(b'help')
             msgbytes = pycompat.bytestr(inst.message)
@@ -487,6 +490,7 @@
             ui.warn(_(b"hg: %s\n") % inst.message)
             ui.warn(_(b"(use 'hg help -v' for a list of global options)\n"))
     except error.UnknownCommand as inst:
+        detailed_exit_code = 10
         nocmdmsg = _(b"hg: unknown command '%s'\n") % inst.command
         try:
             # check if the command is in a disabled extension
@@ -515,7 +519,10 @@
         if not handlecommandexception(ui):
             raise
 
-    return -1
+    if ui.configbool(b'ui', b'detailed-exit-code'):
+        return detailed_exit_code
+    else:
+        return -1
 
 
 def aliasargs(fn, givenargs):
--- a/tests/test-alias.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-alias.t	Thu Jan 14 11:53:55 2021 -0800
@@ -468,13 +468,13 @@
   $ hg i
   hg: command 'i' is ambiguous:
       idalias idaliaslong idaliasshell identify import incoming init
-  [255]
+  [10]
   $ hg id
   042423737847 tip
   $ hg ida
   hg: command 'ida' is ambiguous:
       idalias idaliaslong idaliasshell
-  [255]
+  [10]
   $ hg idalias
   042423737847 tip
   $ hg idaliasl
@@ -484,7 +484,7 @@
   $ hg parentsshell
   hg: command 'parentsshell' is ambiguous:
       parentsshell1 parentsshell2
-  [255]
+  [10]
   $ hg parentsshell1
   one
   $ hg parentsshell2
@@ -533,11 +533,11 @@
   $ hg --cwd .. subalias > /dev/null
   hg: unknown command 'subalias'
   (did you mean idalias?)
-  [255]
+  [10]
   $ hg -R .. subalias > /dev/null
   hg: unknown command 'subalias'
   (did you mean idalias?)
-  [255]
+  [10]
 
 
 shell alias defined in other repo
@@ -545,7 +545,7 @@
   $ hg mainalias > /dev/null
   hg: unknown command 'mainalias'
   (did you mean idalias?)
-  [255]
+  [10]
   $ hg -R .. mainalias
   main
   $ hg --cwd .. mainalias
@@ -555,7 +555,7 @@
   $ hg --cwd .. manalias
   hg: unknown command 'manalias'
   (did you mean one of idalias, mainalias, manifest?)
-  [255]
+  [10]
 
 shell aliases with escaped $ chars
 
@@ -593,7 +593,7 @@
   $ hg reba
   hg: command 'reba' is ambiguous:
       rebase rebate
-  [255]
+  [10]
   $ hg rebat
   this is rebate
   $ hg rebat --foo-bar
@@ -650,22 +650,22 @@
    -T --template TEMPLATE display with template
   
   (use 'hg rt -h' to show more help)
-  [255]
+  [10]
 
 invalid global arguments for normal commands, aliases, and shell aliases
 
   $ hg --invalid root
   hg: option --invalid not recognized
   (use 'hg help -v' for a list of global options)
-  [255]
+  [10]
   $ hg --invalid mylog
   hg: option --invalid not recognized
   (use 'hg help -v' for a list of global options)
-  [255]
+  [10]
   $ hg --invalid blank
   hg: option --invalid not recognized
   (use 'hg help -v' for a list of global options)
-  [255]
+  [10]
 
 environment variable changes in alias commands
 
--- a/tests/test-basic.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-basic.t	Thu Jan 14 11:53:55 2021 -0800
@@ -67,12 +67,12 @@
   $ hg unknown -q 1>&-
   hg: unknown command 'unknown'
   (did you mean debugknown?)
-  [255]
+  [10]
 
   $ hg version -q 2>&-
   Mercurial Distributed SCM * (glob)
   $ hg unknown -q 2>&-
-  [255]
+  [10]
 
   $ hg commit -m test
 
--- a/tests/test-completion.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-completion.t	Thu Jan 14 11:53:55 2021 -0800
@@ -242,7 +242,7 @@
   $ hg debugcomplete --options s
   hg: command 's' is ambiguous:
       serve shelve showconfig status summary
-  [255]
+  [10]
 
 Show all commands + options
   $ hg debugcommands
--- a/tests/test-dispatch.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-dispatch.t	Thu Jan 14 11:53:55 2021 -0800
@@ -29,7 +29,7 @@
    -T --template TEMPLATE   display with template
   
   (use 'hg cat -h' to show more help)
-  [255]
+  [10]
 
 Missing parameter for early option:
 
@@ -110,7 +110,7 @@
   hg log: option -b not recognized
   error in definition for alias 'log': --config may only be given on the command
   line
-  [255]
+  [10]
 
   $ hg log -b '--config=defaults.log=--config=hooks.pre-log=false'
   abort: option --config may not be abbreviated
--- a/tests/test-extension.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-extension.t	Thu Jan 14 11:53:55 2021 -0800
@@ -1018,7 +1018,7 @@
   multirevs command
   
   (use 'hg multirevs -h' to show more help)
-  [255]
+  [10]
 
 
 
@@ -1848,7 +1848,7 @@
   *** (use @command decorator to register 'deprecatedcmd')
   hg: unknown command 'deprecatedcmd'
   (use 'hg help' for a list of commands)
-  [255]
+  [10]
 
  the extension shouldn't be loaded at all so the mq works:
 
@@ -1905,4 +1905,4 @@
   *** (use b'' to make it byte string)
   hg: unknown command 'dummy'
   (did you mean summary?)
-  [255]
+  [10]
--- a/tests/test-fastannotate.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-fastannotate.t	Thu Jan 14 11:53:55 2021 -0800
@@ -123,7 +123,7 @@
   $ hg fastannotate --config fastannotate.modes=fctx -h -q
   hg: unknown command 'fastannotate'
   (did you mean *) (glob)
-  [255]
+  [10]
 
 rename
 
--- a/tests/test-help.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-help.t	Thu Jan 14 11:53:55 2021 -0800
@@ -593,7 +593,7 @@
    -n --dry-run             do not perform actions, just print output
   
   (use 'hg add -h' to show more help)
-  [255]
+  [10]
 
 Test ambiguous command help
 
@@ -763,13 +763,13 @@
   $ hg skjdfks
   hg: unknown command 'skjdfks'
   (use 'hg help' for a list of commands)
-  [255]
+  [10]
 
 Typoed command gives suggestion
   $ hg puls
   hg: unknown command 'puls'
   (did you mean one of pull, push?)
-  [255]
+  [10]
 
 Not enabled extension gets suggested
 
@@ -780,7 +780,7 @@
       rebase        command to move sets of revisions to a different ancestor
   
   (use 'hg help extensions' for information on enabling extensions)
-  [255]
+  [10]
 
 Disabled extension gets suggested
   $ hg --config extensions.rebase=! rebase
@@ -790,7 +790,7 @@
       rebase        command to move sets of revisions to a different ancestor
   
   (use 'hg help extensions' for information on enabling extensions)
-  [255]
+  [10]
 
 Checking that help adapts based on the config:
 
@@ -804,16 +804,16 @@
   $ hg .log
   hg: unknown command '.log'
   (did you mean log?)
-  [255]
+  [10]
 
   $ hg log.
   hg: unknown command 'log.'
   (did you mean log?)
-  [255]
+  [10]
   $ hg pu.lh
   hg: unknown command 'pu.lh'
   (did you mean one of pull, push?)
-  [255]
+  [10]
 
   $ cat > helpext.py <<EOF
   > import os
--- a/tests/test-narrow-trackedcmd.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-narrow-trackedcmd.t	Thu Jan 14 11:53:55 2021 -0800
@@ -118,7 +118,7 @@
                                    web.cacerts config)
   
   (use 'hg tracked -h' to show more help)
-  [255]
+  [10]
   $ hg tracked --import-rules doesnotexist
   abort: cannot read narrowspecs from '$TESTTMP/narrow/doesnotexist': $ENOENT$
   [50]
--- a/tests/test-qrecord.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-qrecord.t	Thu Jan 14 11:53:55 2021 -0800
@@ -105,7 +105,7 @@
   interactively record a new patch
   
   (use 'hg qrecord -h' to show more help)
-  [255]
+  [10]
 
 qrecord patch (mq not present)
 
--- a/tests/test-share-safe.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-share-safe.t	Thu Jan 14 11:53:55 2021 -0800
@@ -92,7 +92,7 @@
       extdiff       command to allow external programs to compare revisions
   
   (use 'hg help extensions' for information on enabling extensions)
-  [255]
+  [10]
 
   $ echo "[extensions]" >> ../source/.hg/hgrc
   $ echo "extdiff=" >> ../source/.hg/hgrc
--- a/tests/test-status-color.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-status-color.t	Thu Jan 14 11:53:55 2021 -0800
@@ -394,7 +394,7 @@
   $ hg unknowncommand > /dev/null
   hg: unknown command 'unknowncommand'
   (use 'hg help' for a list of commands)
-  [255]
+  [10]
 
 color coding of error message without curses
 
@@ -402,6 +402,6 @@
   $ PYTHONPATH=`pwd`:$PYTHONPATH hg unknowncommand > /dev/null
   hg: unknown command 'unknowncommand'
   (use 'hg help' for a list of commands)
-  [255]
+  [10]
 
   $ cd ..
--- a/tests/test-strict.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-strict.t	Thu Jan 14 11:53:55 2021 -0800
@@ -16,7 +16,7 @@
   $ hg an a
   hg: unknown command 'an'
   (use 'hg help' for a list of commands)
-  [255]
+  [10]
   $ hg annotate a
   0: a
 
--- a/tests/test-strip.t	Wed Jan 13 22:37:21 2021 -0800
+++ b/tests/test-strip.t	Thu Jan 14 11:53:55 2021 -0800
@@ -782,7 +782,7 @@
       --mq                    operate on patch repository
   
   (use 'hg debugstrip -h' to show more help)
-  [255]
+  [10]
 
   $ cd ..