# HG changeset patch # User Martin von Zweigbergk # Date 1605892658 28800 # Node ID 600aec73f3091af53677c4dda374c4343a360007 # Parent 98399dd1b96cb4d1990bb693e748a095cd7cb43c errors: format "abort: " text in a new Abort.format() method This remove some duplication we had. Differential Revision: https://phab.mercurial-scm.org/D9348 diff -r 98399dd1b96c -r 600aec73f309 mercurial/chgserver.py --- a/mercurial/chgserver.py Fri Nov 20 08:51:45 2020 -0800 +++ b/mercurial/chgserver.py Fri Nov 20 09:17:38 2020 -0800 @@ -512,9 +512,7 @@ self.cresult.write(b'exit 255') return except error.Abort as inst: - self.ui.error(_(b"abort: %s\n") % inst.message) - if inst.hint: - self.ui.error(_(b"(%s)\n") % inst.hint) + self.ui.error(inst.format()) self.ui.flush() self.cresult.write(b'exit 255') return diff -r 98399dd1b96c -r 600aec73f309 mercurial/dispatch.py --- a/mercurial/dispatch.py Fri Nov 20 08:51:45 2020 -0800 +++ b/mercurial/dispatch.py Fri Nov 20 09:17:38 2020 -0800 @@ -256,9 +256,7 @@ if req.fmsg: req.ui.fmsg = req.fmsg except error.Abort as inst: - ferr.write(_(b"abort: %s\n") % inst.message) - if inst.hint: - ferr.write(_(b"(%s)\n") % inst.hint) + ferr.write(inst.format()) return -1 except error.ParseError as inst: ferr.write(inst.format()) diff -r 98399dd1b96c -r 600aec73f309 mercurial/error.py --- a/mercurial/error.py Fri Nov 20 08:51:45 2020 -0800 +++ b/mercurial/error.py Fri Nov 20 09:17:38 2020 -0800 @@ -182,6 +182,14 @@ # may raise another exception. return pycompat.sysstr(self.__bytes__()) + def format(self): + from .i18n import _ + + message = _(b"abort: %s\n") % self.message + if self.hint: + message += _(b"(%s)\n") % self.hint + return message + class InputError(Abort): """Indicates that the user made an error in their input. diff -r 98399dd1b96c -r 600aec73f309 mercurial/scmutil.py --- a/mercurial/scmutil.py Fri Nov 20 08:51:45 2020 -0800 +++ b/mercurial/scmutil.py Fri Nov 20 09:17:38 2020 -0800 @@ -230,9 +230,7 @@ detailed_exit_code = 30 elif isinstance(inst, error.CanceledError): detailed_exit_code = 250 - ui.error(_(b"abort: %s\n") % inst.message) - if inst.hint: - ui.error(_(b"(%s)\n") % inst.hint) + ui.error(inst.format()) except error.WorkerError as inst: # Don't print a message -- the worker already should have return inst.status_code diff -r 98399dd1b96c -r 600aec73f309 mercurial/wireprotov1server.py --- a/mercurial/wireprotov1server.py Fri Nov 20 08:51:45 2020 -0800 +++ b/mercurial/wireprotov1server.py Fri Nov 20 09:17:38 2020 -0800 @@ -685,9 +685,7 @@ # We did not change it to minimise code change. # This need to be moved to something proper. # Feel free to do it. - procutil.stderr.write(b"abort: %s\n" % exc.message) - if exc.hint is not None: - procutil.stderr.write(b"(%s)\n" % exc.hint) + procutil.stderr.write(exc.format()) procutil.stderr.flush() return wireprototypes.pushres( 0, output.getvalue() if output else b''