extensions: highlight the name of the faulty extensions in the error message
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 29 Nov 2021 13:09:04 +0100
changeset 48408 e4acdf5d94a2
parent 48407 e4e2ce328599
child 48409 0d0ce2529540
extensions: highlight the name of the faulty extensions in the error message This make it easier to understand the message when the extensions name is common. Differential Revision: https://phab.mercurial-scm.org/D11821
mercurial/extensions.py
tests/test-bad-extension.t
tests/test-dispatch.t
tests/test-extension.t
tests/test-largefiles-misc.t
tests/test-lfs.t
tests/test-qrecord.t
tests/test-revset2.t
--- a/mercurial/extensions.py	Fri Nov 26 16:55:34 2021 +0100
+++ b/mercurial/extensions.py	Mon Nov 29 13:09:04 2021 +0100
@@ -307,10 +307,12 @@
             except Exception as inst:
                 msg = stringutil.forcebytestr(inst)
                 if path:
-                    error_msg = _(b"failed to import extension %s from %s: %s")
+                    error_msg = _(
+                        b'failed to import extension "%s" from %s: %s'
+                    )
                     error_msg %= (name, path, msg)
                 else:
-                    error_msg = _(b"failed to import extension %s: %s")
+                    error_msg = _(b'failed to import extension "%s": %s')
                     error_msg %= (name, msg)
                 ui.warn((b"*** %s\n") % error_msg)
                 if isinstance(inst, error.Hint) and inst.hint:
--- a/tests/test-bad-extension.t	Fri Nov 26 16:55:34 2021 +0100
+++ b/tests/test-bad-extension.t	Mon Nov 29 13:09:04 2021 +0100
@@ -52,16 +52,16 @@
   > EOF
 
   $ hg -q help help 2>&1 |grep extension
-  *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow
-  *** failed to import extension badext2: No module named *badext2* (glob)
+  *** failed to import extension "badext" from $TESTTMP/badext.py: bit bucket overflow
+  *** failed to import extension "badext2": No module named 'badext2'
 
 show traceback
 
   $ hg -q help help --traceback 2>&1 | egrep ' extension|^Exception|Traceback|ImportError|ModuleNotFound'
-  *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow
+  *** failed to import extension "badext" from $TESTTMP/badext.py: bit bucket overflow
   Traceback (most recent call last):
   Exception: bit bucket overflow
-  *** failed to import extension badext2: No module named *badext2* (glob)
+  *** failed to import extension "badext2": No module named 'badext2'
   Traceback (most recent call last):
   ImportError: No module named badext2 (no-py3 !)
   ImportError: No module named 'hgext.badext2' (py3 no-py36 !)
@@ -101,7 +101,7 @@
   YYYY/MM/DD HH:MM:SS (PID)>     - invoking registered callbacks: gpg
   YYYY/MM/DD HH:MM:SS (PID)>     > callbacks completed in * (glob)
   YYYY/MM/DD HH:MM:SS (PID)>   - loading extension: badext
-  *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow
+  *** failed to import extension "badext" from $TESTTMP/badext.py: bit bucket overflow
   Traceback (most recent call last):
   Exception: bit bucket overflow
   YYYY/MM/DD HH:MM:SS (PID)>   - loading extension: baddocext
@@ -123,7 +123,7 @@
   Traceback (most recent call last): (py3 !)
   ImportError: No module named 'hgext3rd.badext2' (py3 no-py36 !)
   ModuleNotFoundError: No module named 'hgext3rd.badext2' (py36 !)
-  *** failed to import extension badext2: No module named *badext2* (glob)
+  *** failed to import extension "badext2": No module named 'badext2'
   Traceback (most recent call last):
   ImportError: No module named 'hgext.badext2' (py3 no-py36 !)
   ModuleNotFoundError: No module named 'hgext.badext2' (py36 !)
@@ -160,8 +160,8 @@
 confirm that there's no crash when an extension's documentation is bad
 
   $ hg help --keyword baddocext
-  *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow
-  *** failed to import extension badext2: No module named *badext2* (glob)
+  *** failed to import extension "badext" from $TESTTMP/badext.py: bit bucket overflow
+  *** failed to import extension "badext2": No module named 'badext2'
   Topics:
   
    extensions Using Additional Features
--- a/tests/test-dispatch.t	Fri Nov 26 16:55:34 2021 +0100
+++ b/tests/test-dispatch.t	Mon Nov 29 13:09:04 2021 +0100
@@ -84,7 +84,7 @@
   > raise Exception('bad')
   > EOF
   $ hg log -b '--config=extensions.bad=bad.py' default
-  *** failed to import extension bad from bad.py: bad
+  *** failed to import extension "bad" from bad.py: bad
   abort: option --config may not be abbreviated
   [10]
 
--- a/tests/test-extension.t	Fri Nov 26 16:55:34 2021 +0100
+++ b/tests/test-extension.t	Mon Nov 29 13:09:04 2021 +0100
@@ -649,7 +649,7 @@
 module stub. Our custom lazy importer for Python 2 always returns a stub.
 
   $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.checkrelativity=$TESTTMP/checkrelativity.py checkrelativity) || true
-  *** failed to import extension checkrelativity from $TESTTMP/checkrelativity.py: No module named 'extlibroot.lsub1.lsub2.notexist' (py3 !)
+  *** failed to import extension "checkrelativity" from $TESTTMP/checkrelativity.py: No module named 'extlibroot.lsub1.lsub2.notexist'
   hg: unknown command 'checkrelativity' (py3 !)
   (use 'hg help' for a list of commands) (py3 !)
 
@@ -1882,7 +1882,7 @@
   > EOF
 
   $ hg deprecatedcmd > /dev/null
-  *** failed to import extension deprecatedcmd from $TESTTMP/deprecated/deprecatedcmd.py: missing attributes: norepo, optionalrepo, inferrepo
+  *** failed to import extension "deprecatedcmd" from $TESTTMP/deprecated/deprecatedcmd.py: missing attributes: norepo, optionalrepo, inferrepo
   *** (use @command decorator to register 'deprecatedcmd')
   hg: unknown command 'deprecatedcmd'
   (use 'hg help' for a list of commands)
@@ -1891,7 +1891,7 @@
  the extension shouldn't be loaded at all so the mq works:
 
   $ hg qseries --config extensions.mq= > /dev/null
-  *** failed to import extension deprecatedcmd from $TESTTMP/deprecated/deprecatedcmd.py: missing attributes: norepo, optionalrepo, inferrepo
+  *** failed to import extension "deprecatedcmd" from $TESTTMP/deprecated/deprecatedcmd.py: missing attributes: norepo, optionalrepo, inferrepo
   *** (use @command decorator to register 'deprecatedcmd')
 
   $ cd ..
@@ -1939,7 +1939,7 @@
   > test_unicode_default_value = $TESTTMP/test_unicode_default_value.py
   > EOF
   $ hg -R $TESTTMP/opt-unicode-default dummy
-  *** failed to import extension test_unicode_default_value from $TESTTMP/test_unicode_default_value.py: unicode *'value' found in cmdtable.dummy (glob)
+  *** failed to import extension "test_unicode_default_value" from $TESTTMP/test_unicode_default_value.py: unicode 'value' found in cmdtable.dummy
   *** (use b'' to make it byte string)
   hg: unknown command 'dummy'
   (did you mean summary?)
--- a/tests/test-largefiles-misc.t	Fri Nov 26 16:55:34 2021 +0100
+++ b/tests/test-largefiles-misc.t	Mon Nov 29 13:09:04 2021 +0100
@@ -41,7 +41,7 @@
   > EOF
 
   $ hg config extensions
-  \*\*\* failed to import extension largefiles from missing.py: [Errno *] $ENOENT$: 'missing.py' (glob)
+  \*\*\* failed to import extension "largefiles" from missing.py: [Errno *] $ENOENT$: 'missing.py' (glob)
   abort: repository requires features unknown to this Mercurial: largefiles
   (see https://mercurial-scm.org/wiki/MissingRequirement for more information)
   [255]
--- a/tests/test-lfs.t	Fri Nov 26 16:55:34 2021 +0100
+++ b/tests/test-lfs.t	Mon Nov 29 13:09:04 2021 +0100
@@ -40,7 +40,7 @@
   > EOF
 
   $ hg config extensions
-  \*\*\* failed to import extension lfs from missing.py: [Errno *] $ENOENT$: 'missing.py' (glob)
+  \*\*\* failed to import extension "lfs" from missing.py: [Errno *] $ENOENT$: 'missing.py' (glob)
   abort: repository requires features unknown to this Mercurial: lfs
   (see https://mercurial-scm.org/wiki/MissingRequirement for more information)
   [255]
--- a/tests/test-qrecord.t	Fri Nov 26 16:55:34 2021 +0100
+++ b/tests/test-qrecord.t	Mon Nov 29 13:09:04 2021 +0100
@@ -117,7 +117,7 @@
 
   $ echo "mq=nonexistent" >> $HGRCPATH
   $ hg help qrecord
-  *** failed to import extension mq from nonexistent: [Errno *] * (glob)
+  *** failed to import extension "mq" from nonexistent: [Errno *] * (glob)
   hg qrecord [OPTION]... PATCH [FILE]...
   
   interactively record a new patch
--- a/tests/test-revset2.t	Fri Nov 26 16:55:34 2021 +0100
+++ b/tests/test-revset2.t	Mon Nov 29 13:09:04 2021 +0100
@@ -1601,7 +1601,7 @@
   > EOF
 
   $ hg debugrevspec "custom1()"
-  *** failed to import extension custompredicate from $TESTTMP/custompredicate.py: intentional failure of loading extension
+  *** failed to import extension "custompredicate" from $TESTTMP/custompredicate.py: intentional failure of loading extension
   hg: parse error: unknown identifier: custom1
   [10]