extensions: warn about invalid extensions when listing disabled commands
authorMads Kiilerich <mads@kiilerich.com>
Sun, 26 Dec 2010 00:43:49 +0100
changeset 13191 1aea66b71f4f
parent 13190 5314cbb775f6
child 13193 3bbbde6f3e9f
extensions: warn about invalid extensions when listing disabled commands Invalid extensions in hgext/ could in some cases cause a crash when searching for unknown commands in disabled extensions. With this change we issue a warning if extracting commands from the extensions fails. Traceback is available on request. Reported on https://bugzilla.redhat.com/show_bug.cgi?id=663183 with forest.py.
mercurial/commands.py
mercurial/extensions.py
tests/test-extension.t
--- a/mercurial/commands.py	Wed Dec 22 13:25:00 2010 -0600
+++ b/mercurial/commands.py	Sun Dec 26 00:43:49 2010 +0100
@@ -2034,7 +2034,7 @@
                        'extensions\n'))
 
     def helpextcmd(name):
-        cmd, ext, mod = extensions.disabledcmd(name, ui.config('ui', 'strict'))
+        cmd, ext, mod = extensions.disabledcmd(ui, name, ui.config('ui', 'strict'))
         doc = gettext(mod.__doc__).splitlines()[0]
 
         msg = help.listexts(_("'%s' is provided by the following "
--- a/mercurial/extensions.py	Wed Dec 22 13:25:00 2010 -0600
+++ b/mercurial/extensions.py	Sun Dec 26 00:43:49 2010 +0100
@@ -248,7 +248,7 @@
     if name in paths:
         return _disabledhelp(paths[name])
 
-def disabledcmd(cmd, strict=False):
+def disabledcmd(ui, cmd, strict=False):
     '''import disabled extensions until cmd is found.
     returns (cmdname, extname, doc)'''
 
@@ -266,6 +266,10 @@
                 getattr(mod, 'cmdtable', {}), strict)
         except (error.AmbiguousCommand, error.UnknownCommand):
             return
+        except Exception:
+            ui.warn(_('warning: error finding commands in %s\n') % path)
+            ui.traceback()
+            return
         for c in aliases:
             if c.startswith(cmd):
                 cmd = c
--- a/tests/test-extension.t	Wed Dec 22 13:25:00 2010 -0600
+++ b/tests/test-extension.t	Sun Dec 26 00:43:49 2010 +0100
@@ -315,6 +315,11 @@
   
   use "hg help extensions" for information on enabling extensions
 
+  $ cat > hgext/forest.py <<EOF
+  > cmdtable = None
+  > EOF
   $ hg --config extensions.path=./path.py help foo > /dev/null
+  warning: error finding commands in $TESTTMP/hgext/forest.py
   hg: unknown command 'foo'
+  warning: error finding commands in $TESTTMP/hgext/forest.py
   [255]