comparison mercurial/error.py @ 47303:5a75be916316

errors: create superclass for Abort exception I'd like to let extensions subclass `StorageError` to define a custom exit code. However, `StorageError` does not extend `Abort` (which is where the exit code currently lives), and it seems that it's not supposed to either (`StorageError` seems to be for lower-level errors and `Abort` is for command-level errors). This patch therefore extracts all the code from `Abort` into a new `Error` class, which I'll soon make `StorageError` also extend. Differential Revision: https://phab.mercurial-scm.org/D10738
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 18 May 2021 21:32:12 -0700
parents d9c71bbe20f7
children dd339191f2dc
comparison
equal deleted inserted replaced
47302:d9c71bbe20f7 47303:5a75be916316
49 def __init__(self, *args, **kw): 49 def __init__(self, *args, **kw):
50 self.hint = kw.pop('hint', None) 50 self.hint = kw.pop('hint', None)
51 super(Hint, self).__init__(*args, **kw) 51 super(Hint, self).__init__(*args, **kw)
52 52
53 53
54 class Abort(Hint, Exception): 54 class Error(Hint, Exception):
55 """Raised if a command needs to print an error and exit.""" 55 """Base class for Mercurial errors."""
56 56
57 def __init__( 57 def __init__(
58 self, message, hint=None, coarse_exit_code=None, detailed_exit_code=None 58 self, message, hint=None, coarse_exit_code=None, detailed_exit_code=None
59 ): 59 ):
60 # type: (bytes, Optional[bytes]) -> None 60 # type: (bytes, Optional[bytes]) -> None
83 83
84 message = _(b"abort: %s\n") % self.message 84 message = _(b"abort: %s\n") % self.message
85 if self.hint: 85 if self.hint:
86 message += _(b"(%s)\n") % self.hint 86 message += _(b"(%s)\n") % self.hint
87 return message 87 return message
88
89
90 class Abort(Error):
91 """Raised if a command needs to print an error and exit."""
88 92
89 93
90 class StorageError(Hint, Exception): 94 class StorageError(Hint, Exception):
91 """Raised when an error occurs in a storage layer. 95 """Raised when an error occurs in a storage layer.
92 96