Mercurial > public > mercurial-scm > hg-stable
diff mercurial/dispatch.py @ 46262:9c9e0b4b2ca7
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
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 14 Jan 2021 11:53:55 -0800 |
parents | a9765e0a461d |
children | 52528570312e |
line wrap: on
line diff
--- 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):