[Request] [+- ] D10465: errors: make OutOfBandError extend Abort

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Mon Apr 19 20:04:51 UTC 2021


martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I'm about to create a new `RemoteError` exception and make
  `OutOfBandError` extend it. This patch prepares for that.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10465

AFFECTED FILES
  mercurial/error.py
  mercurial/scmutil.py

CHANGE DETAILS

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -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):
diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -304,10 +304,20 @@
         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, hint=None):
+        # type: () -> bytes
+        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, hint=hint)
 
 
 class ParseError(Abort):



To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20210419/9314a11f/attachment-0001.html>


More information about the Mercurial-patches mailing list