Patchwork extensions: suggest --config extensions.bad=! when bad fails

login
register
mail settings
Submitter timeless@mozdev.org
Date Sept. 18, 2015, 11:38 a.m.
Message ID <5f61789ec5c7e1f6277f.1442576324@waste.org>
Download mbox | patch
Permalink /patch/10544/
State Deferred
Headers show

Comments

timeless@mozdev.org - Sept. 18, 2015, 11:38 a.m.
# HG changeset patch
# User timeless@mozdev.org
# Date 1441928905 14400
#      Thu Sep 10 19:48:25 2015 -0400
# Node ID 5f61789ec5c7e1f6277fb857d4c61214a857b0cd
# Parent  a0eff7ebc2aebb32cf4c8da276104102ff37d786
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.
Pierre-Yves David - Sept. 22, 2015, 9:53 p.m.
On 09/18/2015 04:38 AM, timeless@mozdev.org wrote:
> # HG changeset patch
> # User timeless@mozdev.org
> # Date 1441928905 14400
> #      Thu Sep 10 19:48:25 2015 -0400
> # Node ID 5f61789ec5c7e1f6277fb857d4c61214a857b0cd
> # Parent  a0eff7ebc2aebb32cf4c8da276104102ff37d786
> 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.

Not entirely enthousiastic about it. IF a user enable an extensions it 
should be able to disable it. But knowing that users are users, this is 
probably a bit too optimistic.

However, temporary (--config) way to disable extensions is probably a 
bad sugguest in the "fail to import case" where there is low chance this 
will start importing again for the next run.

Hi like Kevin proposal of listing all possible offender instead of the 
first one.

> 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 %(n)s from %(p)s: %(i)s\n"
> +                          "(you can use '--config extensions.%(n)s=!' to disable it)\n")
> +                        % {'n': name, 'p': path, 'i': inst})
>               else:
> -                ui.warn(_("*** failed to import extension %s: %s\n")
> -                        % (name, inst))
> +                ui.warn(_("*** failed to import extension %(n)s: %(i)s\n"
> +                          "(you can use '--config extensions.%(n)s=!' to disable it)\n")
> +                        % {'n': name, 'i': inst})
>               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=!' 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=!' 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=!' 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=!' to disable it)
>     hg qrecord [OPTION]... PATCH [FILE]...
>
>     interactively record a new patch
timeless - Sept. 24, 2015, 6:26 p.m.
On Tue, Sep 22, 2015 at 5:53 PM, Pierre-Yves David
<pierre-yves.david@ens-lyon.org> wrote:
> Not entirely enthousiastic about it. IF a user enable an extensions it
> should be able to disable it. But knowing that users are users, this is
> probably a bit too optimistic.
>
> However, temporary (--config) way to disable extensions is probably a bad
> sugguest in the "fail to import case" where there is low chance this will
> start importing again for the next run.

Depends. If something is automatically maintaining the extension (a
package manager, a VCS), then it might magically fix itself (this
happens to me often enough).

> Hi like Kevin proposal of listing all possible offender instead of the first
> one.

I'm not sure what you mean by "all possible offenders". Each thing
that fails to load gets its own line item, as shown in the test.

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 %(n)s from %(p)s: %(i)s\n"
+                          "(you can use '--config extensions.%(n)s=!' to disable it)\n")
+                        % {'n': name, 'p': path, 'i': inst})
             else:
-                ui.warn(_("*** failed to import extension %s: %s\n")
-                        % (name, inst))
+                ui.warn(_("*** failed to import extension %(n)s: %(i)s\n"
+                          "(you can use '--config extensions.%(n)s=!' to disable it)\n")
+                        % {'n': name, 'i': inst})
             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=!' 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=!' 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=!' 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=!' to disable it)
   hg qrecord [OPTION]... PATCH [FILE]...
   
   interactively record a new patch