changeset 45885:600aec73f309

errors: format "abort: " text in a new Abort.format() method This remove some duplication we had. Differential Revision: https://phab.mercurial-scm.org/D9348
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 20 Nov 2020 09:17:38 -0800
parents 98399dd1b96c
children 18489e26d9a0
files mercurial/chgserver.py mercurial/dispatch.py mercurial/error.py mercurial/scmutil.py mercurial/wireprotov1server.py
diffstat 5 files changed, 12 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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())
--- 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.
--- 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
--- 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''