errors: make OutOfBandError extend Abort
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 19 Apr 2021 10:49:15 -0700
changeset 46975 14ddb1dca2c0
parent 46974 3c9208702db3
child 46976 f9482db16cef
errors: make OutOfBandError extend Abort I'm about to create a new `RemoteError` exception and make `OutOfBandError` extend it. This patch prepares for that. Differential Revision: https://phab.mercurial-scm.org/D10465
mercurial/error.py
mercurial/scmutil.py
--- a/mercurial/error.py	Mon Apr 05 12:22:25 2021 +0200
+++ b/mercurial/error.py	Mon Apr 19 10:49:15 2021 -0700
@@ -304,10 +304,19 @@
         Abort.__init__(self, _(b'response expected'))
 
 
-class OutOfBandError(Hint, Exception):
+class OutOfBandError(Abort):
     """Exception raised when a remote repo reports failure"""
 
-    __bytes__ = _tobytes
+    def __init__(self, *messages, **kwargs):
+        from .i18n import _
+
+        if messages:
+            message = _(b"remote error:\n%s") % b''.join(messages)
+            # Abort.format() adds a trailing newline
+            message = message.rstrip(b'\n')
+        else:
+            message = _(b"remote error")
+        super(OutOfBandError, self).__init__(message, **kwargs)
 
 
 class ParseError(Abort):
--- a/mercurial/scmutil.py	Mon Apr 05 12:22:25 2021 +0200
+++ b/mercurial/scmutil.py	Mon Apr 19 10:49:15 2021 -0700
@@ -181,17 +181,6 @@
                 encoding.strtolocal(inst.strerror),
             )
         )
-    except error.OutOfBandError as inst:
-        detailed_exit_code = 100
-        if inst.args:
-            msg = _(b"abort: remote error:\n")
-        else:
-            msg = _(b"abort: remote error\n")
-        ui.error(msg)
-        if inst.args:
-            ui.error(b''.join(inst.args))
-        if inst.hint:
-            ui.error(b'(%s)\n' % inst.hint)
     except error.RepoError as inst:
         ui.error(_(b"abort: %s\n") % inst)
         if inst.hint:
@@ -233,6 +222,8 @@
             detailed_exit_code = 30
         elif isinstance(inst, error.HookAbort):
             detailed_exit_code = 40
+        elif isinstance(inst, error.OutOfBandError):
+            detailed_exit_code = 100
         elif isinstance(inst, error.SecurityError):
             detailed_exit_code = 150
         elif isinstance(inst, error.CanceledError):