D9346: errors: create "similarity hint" for UnknownIdentifier eagerly in constructor
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Sat Nov 21 00:26:39 UTC 2020
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
No code wanted to do anything but to produce a hint from it anyway, so
we might as well just store the hint in the exception (which already
extended `Hint`). That way we can easily convert it to a
`ConfigException` when it's parsing of configuration that fails.
I was wondering if the purpose of lazily creating the string was so we
don't create it in cases where it won't get printed anyway. However, I
couldn't find any places where that could happen. If we do find such
places, we could instead revert to making it lazy but add a function
on `UnknownIdentifier` for creating the hint string.
I dropped the comment saying "make sure to check fileset first, as
revset can invoke fileset", which was added in 4e240d6ab898 <https://phab.mercurial-scm.org/rHG4e240d6ab8981932dc75ecb3129d08c9c59a8649> (dispatch:
offer near-edit-distance suggestions for {file,rev}set functions,
2015-01-26). I couldn't figure out what it meant. The author of that
patch also did not remember the reason for it. Perhaps changes that
have happened since then made it so it no longer matters.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D9346
AFFECTED FILES
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
@@ -150,13 +150,7 @@
)
else:
write(_(b"hg: parse error: %s\n") % inst.message)
- if isinstance(inst, error.UnknownIdentifier):
- # make sure to check fileset first, as revset can invoke fileset
- similar = error.getsimilar(inst.symbols, inst.function)
- hint = error.similarity_hint(similar)
- if hint:
- write(b"(%s)\n" % hint)
- elif inst.hint:
+ if inst.hint:
write(_(b"(%s)\n") % inst.hint)
diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -297,9 +297,12 @@
def __init__(self, function, symbols):
from .i18n import _
- ParseError.__init__(self, _(b"unknown identifier: %s") % function)
- self.function = function
- self.symbols = symbols
+ similar = getsimilar(symbols, function)
+ hint = similarity_hint(similar)
+
+ ParseError.__init__(
+ self, _(b"unknown identifier: %s") % function, hint=hint
+ )
class RepoError(Hint, Exception):
To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list