Patchwork D9348: errors: format "abort: " text in a new Abort.format() method

login
register
mail settings
Submitter phabricator
Date Nov. 21, 2020, 12:26 a.m.
Message ID <differential-rev-PHID-DREV-cflvi52gthuxorixagz2-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47632/
State Superseded
Headers show

Comments

phabricator - Nov. 21, 2020, 12:26 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This remove some duplication we had.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/chgserver.py
  mercurial/dispatch.py
  mercurial/error.py
  mercurial/scmutil.py
  mercurial/wireprotov1server.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/wireprotov1server.py b/mercurial/wireprotov1server.py
--- a/mercurial/wireprotov1server.py
+++ b/mercurial/wireprotov1server.py
@@ -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''
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -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 --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -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 --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -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 --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -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