diff mercurial/scmutil.py @ 47289:33c0c25d0b0f

errors: let each Abort subclass define its error code It's more flexible to have the error codes defined on the error types themselves. That way extensions can easily set their own exit code. It also means that we can reduce a bit of duplication betwen `scmutil.callcatch()` and `chgserver.chgcmdserver.validate()`. Differential Revision: https://phab.mercurial-scm.org/D10735
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 18 May 2021 17:15:49 -0700
parents bea4717415c0
children d9c71bbe20f7
line wrap: on
line diff
--- a/mercurial/scmutil.py	Wed May 19 15:10:49 2021 +0200
+++ b/mercurial/scmutil.py	Tue May 18 17:15:49 2021 -0700
@@ -212,20 +212,8 @@
     except error.WdirUnsupported:
         ui.error(_(b"abort: working directory revision cannot be specified\n"))
     except error.Abort as inst:
-        if isinstance(inst, (error.InputError, error.ParseError)):
-            detailed_exit_code = 10
-        elif isinstance(inst, error.StateError):
-            detailed_exit_code = 20
-        elif isinstance(inst, error.ConfigError):
-            detailed_exit_code = 30
-        elif isinstance(inst, error.HookAbort):
-            detailed_exit_code = 40
-        elif isinstance(inst, error.RemoteError):
-            detailed_exit_code = 100
-        elif isinstance(inst, error.SecurityError):
-            detailed_exit_code = 150
-        elif isinstance(inst, error.CanceledError):
-            detailed_exit_code = 250
+        if inst.detailed_exit_code is not None:
+            detailed_exit_code = inst.detailed_exit_code
         ui.error(inst.format())
     except error.WorkerError as inst:
         # Don't print a message -- the worker already should have