Patchwork D10465: errors: make OutOfBandError extend Abort

login
register
mail settings
Submitter phabricator
Date April 19, 2021, 8:04 p.m.
Message ID <differential-rev-PHID-DREV-rmovjj6m23yhvo4c3cpi-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48782/
State Superseded
Headers show

Comments

phabricator - April 19, 2021, 8:04 p.m.
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




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

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):