Patchwork [2,of,2] extensions: suggest --config extensions.bad=! when bad fails

login
register
mail settings
Submitter timeless@mozdev.org
Date Sept. 11, 2015, 12:32 a.m.
Message ID <d7d94ed8a182092c2f66.1441931540@waste.org>
Download mbox | patch
Permalink /patch/10477/
State Accepted
Headers show

Comments

timeless@mozdev.org - Sept. 11, 2015, 12:32 a.m.
# HG changeset patch
# User timeless@mozdev.org
# Date 1441928905 14400
#      Thu Sep 10 19:48:25 2015 -0400
# Node ID d7d94ed8a182092c2f667b915be972e9c1de9e0b
# Parent  cc7fc4b67ea0880faa4f8d823ba8fc348f71c0f9
extensions: suggest --config extensions.bad=! when bad fails

There are lots of ways for extensions to fail, so users should
be given a hint about how to deal with them, instead of being
left to scratch their heads.
Augie Fackler - Sept. 14, 2015, 2:35 a.m.
On Thu, Sep 10, 2015 at 07:32:20PM -0500, timeless@mozdev.org wrote:
> # HG changeset patch
> # User timeless@mozdev.org
> # Date 1441928905 14400
> #      Thu Sep 10 19:48:25 2015 -0400
> # Node ID d7d94ed8a182092c2f667b915be972e9c1de9e0b
> # Parent  cc7fc4b67ea0880faa4f8d823ba8fc348f71c0f9
> extensions: suggest --config extensions.bad=! when bad fails
>
> There are lots of ways for extensions to fail, so users should
> be given a hint about how to deal with them, instead of being
> left to scratch their heads.
>
> diff --git a/mercurial/extensions.py b/mercurial/extensions.py
> --- a/mercurial/extensions.py
> +++ b/mercurial/extensions.py
> @@ -119,11 +119,13 @@
>              raise
>          except Exception as inst:
>              if path:
> -                ui.warn(_("*** failed to import extension %s from %s: %s\n")
> -                        % (name, path, inst))
> +                ui.warn(_("*** failed to import extension %s from %s: %s\n"
> +                          "(you can use '--config extensions.%s=!%s' to disable it)\n")
> +                        % (name, path, inst, name, path))
>              else:
> -                ui.warn(_("*** failed to import extension %s: %s\n")
> -                        % (name, inst))
> +                ui.warn(_("*** failed to import extension %s: %s\n"
> +                          "(you can use '--config extensions.%s=!' to disable it)\n")
> +                        % (name, inst, name))
>              ui.traceback()
>
>      for name in _order[newindex:]:
> diff --git a/tests/test-bad-extension.t b/tests/test-bad-extension.t
> --- a/tests/test-bad-extension.t
> +++ b/tests/test-bad-extension.t
> @@ -11,15 +11,19 @@
>
>    $ hg -q help help 2>&1 |grep extension
>    *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow
> +  (you can use '--config extensions.badext=!$TESTTMP/badext.py' to disable it)

is specifying the path to the extension needed here? can't it just be
extensions.badext=! ?

>    *** failed to import extension badext2: No module named badext2
> +  (you can use '--config extensions.badext2=!' to disable it)
>
>  show traceback
>
>    $ hg -q help help --traceback 2>&1 | egrep ' extension|^Exception|Traceback|ImportError'
>    *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow
> +  (you can use '--config extensions.badext=!$TESTTMP/badext.py' to disable it)
>    Traceback (most recent call last):
>    Exception: bit bucket overflow
>    *** failed to import extension badext2: No module named badext2
> +  (you can use '--config extensions.badext2=!' to disable it)
>    Traceback (most recent call last):
>    ImportError: No module named badext2
>
> @@ -30,11 +34,13 @@
>    > | grep -v '^ ' \
>    > | egrep 'extension..[^p]|^Exception|Traceback|ImportError|not import'
>    *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow
> +  (you can use '--config extensions.badext=!$TESTTMP/badext.py' to disable it)
>    Traceback (most recent call last):
>    Exception: bit bucket overflow
>    could not import hgext.badext2 (No module named badext2): trying badext2
>    Traceback (most recent call last):
>    ImportError: No module named badext2
>    *** failed to import extension badext2: No module named badext2
> +  (you can use '--config extensions.badext2=!' to disable it)
>    Traceback (most recent call last):
>    ImportError: No module named badext2
> diff --git a/tests/test-qrecord.t b/tests/test-qrecord.t
> --- a/tests/test-qrecord.t
> +++ b/tests/test-qrecord.t
> @@ -110,6 +110,7 @@
>    $ echo "mq=nonexistent" >> $HGRCPATH
>    $ hg help qrecord
>    *** failed to import extension mq from nonexistent: [Errno *] * (glob)
> +  (you can use '--config extensions.mq=!nonexistent' to disable it)
>    hg qrecord [OPTION]... PATCH [FILE]...
>
>    interactively record a new patch
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
timeless - Sept. 16, 2015, 1:23 a.m.
Augie Fackler wrote:
> > +  (you can use '--config extensions.badext=!$TESTTMP/badext.py' to
disable it)
>
> is specifying the path to the extension needed here? can't it just be
> extensions.badext=! ?

I haven't worked through the logic, I think there's some value in
discovering this feature, but it's possible that a simple "!" is enough.

Patch

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -119,11 +119,13 @@ 
             raise
         except Exception as inst:
             if path:
-                ui.warn(_("*** failed to import extension %s from %s: %s\n")
-                        % (name, path, inst))
+                ui.warn(_("*** failed to import extension %s from %s: %s\n"
+                          "(you can use '--config extensions.%s=!%s' to disable it)\n")
+                        % (name, path, inst, name, path))
             else:
-                ui.warn(_("*** failed to import extension %s: %s\n")
-                        % (name, inst))
+                ui.warn(_("*** failed to import extension %s: %s\n"
+                          "(you can use '--config extensions.%s=!' to disable it)\n")
+                        % (name, inst, name))
             ui.traceback()
 
     for name in _order[newindex:]:
diff --git a/tests/test-bad-extension.t b/tests/test-bad-extension.t
--- a/tests/test-bad-extension.t
+++ b/tests/test-bad-extension.t
@@ -11,15 +11,19 @@ 
 
   $ hg -q help help 2>&1 |grep extension
   *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow
+  (you can use '--config extensions.badext=!$TESTTMP/badext.py' to disable it)
   *** failed to import extension badext2: No module named badext2
+  (you can use '--config extensions.badext2=!' to disable it)
 
 show traceback
 
   $ hg -q help help --traceback 2>&1 | egrep ' extension|^Exception|Traceback|ImportError'
   *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow
+  (you can use '--config extensions.badext=!$TESTTMP/badext.py' to disable it)
   Traceback (most recent call last):
   Exception: bit bucket overflow
   *** failed to import extension badext2: No module named badext2
+  (you can use '--config extensions.badext2=!' to disable it)
   Traceback (most recent call last):
   ImportError: No module named badext2
 
@@ -30,11 +34,13 @@ 
   > | grep -v '^ ' \
   > | egrep 'extension..[^p]|^Exception|Traceback|ImportError|not import'
   *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow
+  (you can use '--config extensions.badext=!$TESTTMP/badext.py' to disable it)
   Traceback (most recent call last):
   Exception: bit bucket overflow
   could not import hgext.badext2 (No module named badext2): trying badext2
   Traceback (most recent call last):
   ImportError: No module named badext2
   *** failed to import extension badext2: No module named badext2
+  (you can use '--config extensions.badext2=!' to disable it)
   Traceback (most recent call last):
   ImportError: No module named badext2
diff --git a/tests/test-qrecord.t b/tests/test-qrecord.t
--- a/tests/test-qrecord.t
+++ b/tests/test-qrecord.t
@@ -110,6 +110,7 @@ 
   $ echo "mq=nonexistent" >> $HGRCPATH
   $ hg help qrecord
   *** failed to import extension mq from nonexistent: [Errno *] * (glob)
+  (you can use '--config extensions.mq=!nonexistent' to disable it)
   hg qrecord [OPTION]... PATCH [FILE]...
   
   interactively record a new patch