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: (Any, Optional[bytes]) -> None + 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): 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):