comparison mercurial/error.py @ 45898: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
45897:8cc9e7f762d6 45898:1817b66897ad
295 """Exception raised when a {rev,file}set references an unknown identifier""" 295 """Exception raised when a {rev,file}set references an unknown identifier"""
296 296
297 def __init__(self, function, symbols): 297 def __init__(self, function, symbols):
298 from .i18n import _ 298 from .i18n import _
299 299
300 ParseError.__init__(self, _(b"unknown identifier: %s") % function) 300 similar = getsimilar(symbols, function)
301 self.function = function 301 hint = similarity_hint(similar)
302 self.symbols = symbols 302
303 ParseError.__init__(
304 self, _(b"unknown identifier: %s") % function, hint=hint
305 )
303 306
304 307
305 class RepoError(Hint, Exception): 308 class RepoError(Hint, Exception):
306 __bytes__ = _tobytes 309 __bytes__ = _tobytes
307 310