diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py --- a/mercurial/chgserver.py +++ b/mercurial/chgserver.py @@ -62,7 +62,6 @@ from . import ( extensions, node, pycompat, - scmutil, util, ) @@ -508,7 +507,7 @@ class chgcmdserver(commandserver.server) try: self.ui, lui = _loadnewui(self.ui, args, self.cdebug) except error.ParseError as inst: - scmutil.formatparse(self.ui.warn, inst) + self.ui.warn(inst.format()) self.ui.flush() self.cresult.write(b'exit 255') return diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -261,7 +261,7 @@ def dispatch(req): ferr.write(_(b"(%s)\n") % inst.hint) return -1 except error.ParseError as inst: - scmutil.formatparse(ferr.write, inst) + ferr.write(inst.format()) return -1 msg = _formatargs(req.args) @@ -469,7 +469,7 @@ def _callcatch(ui, func): ui.warn(_(b"hg: %s\n") % inst.message) ui.warn(_(b"(use 'hg help -v' for a list of global options)\n")) except error.ParseError as inst: - scmutil.formatparse(ui.warn, inst) + ui.warn(inst.format()) return -1 except error.UnknownCommand as inst: nocmdmsg = _(b"hg: unknown command '%s'\n") % inst.command diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -267,6 +267,20 @@ class ParseError(Hint, Exception): __bytes__ = _tobytes + def format(self): + from .i18n import _ + + if self.location is not None: + message = _(b"hg: parse error at %s: %s\n") % ( + pycompat.bytestr(self.location), + self.message, + ) + else: + message = _(b"hg: parse error: %s\n") % self.message + if self.hint: + message += _(b"(%s)\n") % self.hint + return message + class PatchError(Exception): __bytes__ = _tobytes diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -142,18 +142,6 @@ def nochangesfound(ui, repo, excluded=No ui.status(_(b"no changes found\n")) -def formatparse(write, inst): - if inst.location is not None: - write( - _(b"hg: parse error at %s: %s\n") - % (pycompat.bytestr(inst.location), inst.message) - ) - else: - write(_(b"hg: parse error: %s\n") % inst.message) - if inst.hint: - write(_(b"(%s)\n") % inst.hint) - - def callcatch(ui, func): """call func() with global exception handling