errors: move Abort earlier, so more exceptions can subclass it
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 18 May 2021 21:58:12 -0700
changeset 47290 5e736d2e9703
parent 47289 33c0c25d0b0f
child 47291 d9c71bbe20f7
errors: move Abort earlier, so more exceptions can subclass it I'd like to make at least `InterventionRequired` subclass `Abort` and Python requires the superclass to be defined before the subtype. Differential Revision: https://phab.mercurial-scm.org/D10736
mercurial/error.py
--- a/mercurial/error.py	Tue May 18 17:15:49 2021 -0700
+++ b/mercurial/error.py	Tue May 18 21:58:12 2021 -0700
@@ -51,6 +51,39 @@
         super(Hint, self).__init__(*args, **kw)
 
 
+class Abort(Hint, Exception):
+    """Raised if a command needs to print an error and exit."""
+
+    def __init__(self, message, hint=None, detailed_exit_code=None):
+        # type: (bytes, Optional[bytes]) -> None
+        self.message = message
+        self.hint = hint
+        self.detailed_exit_code = detailed_exit_code
+        # Pass the message into the Exception constructor to help extensions
+        # that look for exc.args[0].
+        Exception.__init__(self, message)
+
+    def __bytes__(self):
+        return self.message
+
+    if pycompat.ispy3:
+
+        def __str__(self):
+            # the output would be unreadable if the message was translated,
+            # but do not replace it with encoding.strfromlocal(), which
+            # may raise another exception.
+            return pycompat.sysstr(self.__bytes__())
+
+    def format(self):
+        # type: () -> bytes
+        from .i18n import _
+
+        message = _(b"abort: %s\n") % self.message
+        if self.hint:
+            message += _(b"(%s)\n") % self.hint
+        return message
+
+
 class StorageError(Hint, Exception):
     """Raised when an error occurs in a storage layer.
 
@@ -182,39 +215,6 @@
         )
 
 
-class Abort(Hint, Exception):
-    """Raised if a command needs to print an error and exit."""
-
-    def __init__(self, message, hint=None, detailed_exit_code=None):
-        # type: (bytes, Optional[bytes]) -> None
-        self.message = message
-        self.hint = hint
-        self.detailed_exit_code = detailed_exit_code
-        # Pass the message into the Exception constructor to help extensions
-        # that look for exc.args[0].
-        Exception.__init__(self, message)
-
-    def __bytes__(self):
-        return self.message
-
-    if pycompat.ispy3:
-
-        def __str__(self):
-            # the output would be unreadable if the message was translated,
-            # but do not replace it with encoding.strfromlocal(), which
-            # may raise another exception.
-            return pycompat.sysstr(self.__bytes__())
-
-    def format(self):
-        # type: () -> bytes
-        from .i18n import _
-
-        message = _(b"abort: %s\n") % self.message
-        if self.hint:
-            message += _(b"(%s)\n") % self.hint
-        return message
-
-
 class InputError(Abort):
     """Indicates that the user made an error in their input.