comparison mercurial/error.py @ 47291:d9c71bbe20f7

errors: make InterventionRequired subclass Abort The docstring for `Abort` says that it's for errors raised by commands and `InterventionRequired` is definitely something raised by commands, so it seems that it should be an `Abort`. This patch makes it so. It adds a `coarse_exit_code` (in addition to the already existing `detailed_exit_code`) to `Abort` to achieve that, since `InterventionRequired` should result in a special exit code even when the `ui.detailed-exit-code` config is not set. Differential Revision: https://phab.mercurial-scm.org/D10737
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 18 May 2021 22:07:16 -0700
parents 5e736d2e9703
children 5a75be916316
comparison
equal deleted inserted replaced
47290:5e736d2e9703 47291:d9c71bbe20f7
52 52
53 53
54 class Abort(Hint, Exception): 54 class Abort(Hint, Exception):
55 """Raised if a command needs to print an error and exit.""" 55 """Raised if a command needs to print an error and exit."""
56 56
57 def __init__(self, message, hint=None, detailed_exit_code=None): 57 def __init__(
58 self, message, hint=None, coarse_exit_code=None, detailed_exit_code=None
59 ):
58 # type: (bytes, Optional[bytes]) -> None 60 # type: (bytes, Optional[bytes]) -> None
59 self.message = message 61 self.message = message
60 self.hint = hint 62 self.hint = hint
63 self.coarse_exit_code = coarse_exit_code
61 self.detailed_exit_code = detailed_exit_code 64 self.detailed_exit_code = detailed_exit_code
62 # Pass the message into the Exception constructor to help extensions 65 # Pass the message into the Exception constructor to help extensions
63 # that look for exc.args[0]. 66 # that look for exc.args[0].
64 Exception.__init__(self, message) 67 Exception.__init__(self, message)
65 68
190 super(WorkerError, self).__init__(status_code) 193 super(WorkerError, self).__init__(status_code)
191 194
192 __bytes__ = _tobytes 195 __bytes__ = _tobytes
193 196
194 197
195 class InterventionRequired(Hint, Exception): 198 class InterventionRequired(Abort):
196 """Exception raised when a command requires human intervention.""" 199 """Exception raised when a command requires human intervention."""
197 200
198 __bytes__ = _tobytes 201 def __init__(self, message, hint=None):
202 super(InterventionRequired, self).__init__(
203 message, hint=hint, coarse_exit_code=1, detailed_exit_code=240
204 )
205
206 def format(self):
207 # type: () -> bytes
208 from .i18n import _
209
210 message = _(b"%s\n") % self.message
211 if self.hint:
212 message += _(b"(%s)\n") % self.hint
213 return message
199 214
200 215
201 class ConflictResolutionRequired(InterventionRequired): 216 class ConflictResolutionRequired(InterventionRequired):
202 """Exception raised when a continuable command required merge conflict resolution.""" 217 """Exception raised when a continuable command required merge conflict resolution."""
203 218