changeset 45880:7a273336d3d3

errors: restructure formatparse() to clarify conditions a bit The `similar` list will be calculated only for `error.UnknownIdentifier`. It was then printed only if `inst.location is None`, which is true for that exception type, but it's an indirect condition to rely on. Also, it looked from the code like it could both report similarities and print a hint. That would be a little awkward because the similarity report looks similar to the hint (both are printed within parentheses). I also added a `elif` to clarify that. I plan to refactor this more coming patches so the similarity report actually is a hint. Differential Revision: https://phab.mercurial-scm.org/D9343
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 19 Nov 2020 10:29:06 -0800
parents 5d73d3053d92
children bb1b7a5bc96b
files mercurial/scmutil.py
diffstat 1 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/scmutil.py	Thu Nov 19 14:55:55 2020 -0500
+++ b/mercurial/scmutil.py	Thu Nov 19 10:29:06 2020 -0800
@@ -159,10 +159,6 @@
 
 
 def formatparse(write, inst):
-    similar = []
-    if isinstance(inst, error.UnknownIdentifier):
-        # make sure to check fileset first, as revset can invoke fileset
-        similar = getsimilar(inst.symbols, inst.function)
     if inst.location is not None:
         write(
             _(b"hg: parse error at %s: %s\n")
@@ -170,8 +166,11 @@
         )
     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 = getsimilar(inst.symbols, inst.function)
         reportsimilar(write, similar)
-    if inst.hint:
+    elif inst.hint:
         write(_(b"(%s)\n") % inst.hint)