comparison mercurial/scmutil.py @ 45883:1817b66897ad

errors: create "similarity hint" for UnknownIdentifier eagerly in constructor 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 (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. Differential Revision: https://phab.mercurial-scm.org/D9346
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 19 Nov 2020 11:23:59 -0800
parents 8cc9e7f762d6
children 98399dd1b96c
comparison
equal deleted inserted replaced
45882:8cc9e7f762d6 45883:1817b66897ad
148 _(b"hg: parse error at %s: %s\n") 148 _(b"hg: parse error at %s: %s\n")
149 % (pycompat.bytestr(inst.location), inst.message) 149 % (pycompat.bytestr(inst.location), inst.message)
150 ) 150 )
151 else: 151 else:
152 write(_(b"hg: parse error: %s\n") % inst.message) 152 write(_(b"hg: parse error: %s\n") % inst.message)
153 if isinstance(inst, error.UnknownIdentifier): 153 if inst.hint:
154 # make sure to check fileset first, as revset can invoke fileset
155 similar = error.getsimilar(inst.symbols, inst.function)
156 hint = error.similarity_hint(similar)
157 if hint:
158 write(b"(%s)\n" % hint)
159 elif inst.hint:
160 write(_(b"(%s)\n") % inst.hint) 154 write(_(b"(%s)\n") % inst.hint)
161 155
162 156
163 def callcatch(ui, func): 157 def callcatch(ui, func):
164 """call func() with global exception handling 158 """call func() with global exception handling