Patchwork D10466: errors: introduce a class for remote errors

login
register
mail settings
Submitter phabricator
Date April 19, 2021, 8:04 p.m.
Message ID <differential-rev-PHID-DREV-jacgiq7wpgdpvc64rnyy-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48783/
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
  Having an exception for remote errors makes it much easier to exit
  with the right detailed exit code.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -222,7 +222,7 @@ 
             detailed_exit_code = 30
         elif isinstance(inst, error.HookAbort):
             detailed_exit_code = 40
-        elif isinstance(inst, error.OutOfBandError):
+        elif isinstance(inst, error.RemoteError):
             detailed_exit_code = 100
         elif isinstance(inst, error.SecurityError):
             detailed_exit_code = 150
diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -304,7 +304,13 @@ 
         Abort.__init__(self, _(b'response expected'))
 
 
-class OutOfBandError(Abort):
+class RemoteError(Abort):
+    """Exception raised when interacting with a remote repo fails"""
+
+    __bytes__ = _tobytes
+
+
+class OutOfBandError(RemoteError):
     """Exception raised when a remote repo reports failure"""
 
     def __init__(self, *messages, hint=None):