D9347: errors: make formatparse() an instance method on ParseError
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Sat Nov 21 00:26:42 UTC 2020
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
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).
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D9347
AFFECTED FILES
mercurial/chgserver.py
mercurial/dispatch.py
mercurial/error.py
mercurial/scmutil.py
CHANGE DETAILS
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -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
diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -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
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -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
diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -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
To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list