Mercurial > hg
changeset 45884:98399dd1b96c
errors: make formatparse() an instance method on ParseError
It's just a little simpler this way.
Don't ask me what the "hg: " prefix signifies to the user, I just left
it as it was. I think we should consider changing the prefixes later
(maybe always use "abort: ", or maybe use more specific prefixes in
general).
Differential Revision: https://phab.mercurial-scm.org/D9347
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 20 Nov 2020 08:51:45 -0800 |
parents | 1817b66897ad |
children | 600aec73f309 |
files | mercurial/chgserver.py mercurial/dispatch.py mercurial/error.py mercurial/scmutil.py |
diffstat | 4 files changed, 17 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/chgserver.py Thu Nov 19 11:23:59 2020 -0800 +++ b/mercurial/chgserver.py Fri Nov 20 08:51:45 2020 -0800 @@ -62,7 +62,6 @@ extensions, node, pycompat, - scmutil, util, ) @@ -508,7 +507,7 @@ 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
--- a/mercurial/dispatch.py Thu Nov 19 11:23:59 2020 -0800 +++ b/mercurial/dispatch.py Fri Nov 20 08:51:45 2020 -0800 @@ -261,7 +261,7 @@ 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 @@ 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
--- a/mercurial/error.py Thu Nov 19 11:23:59 2020 -0800 +++ b/mercurial/error.py Fri Nov 20 08:51:45 2020 -0800 @@ -267,6 +267,20 @@ __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
--- a/mercurial/scmutil.py Thu Nov 19 11:23:59 2020 -0800 +++ b/mercurial/scmutil.py Fri Nov 20 08:51:45 2020 -0800 @@ -142,18 +142,6 @@ 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