[PATCH STABLE] dispatch: don't mangle abort messages from ImportErrors during commands

Dan Villiom Podlaski Christiansen danchr at gmail.com
Fri Apr 30 11:12:55 CDT 2010


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1272643916 -7200
# Node ID c7c7ad58ccd0928f419e4038e1a844dd7fd538a0
# Parent  3852b30449fee1151fdf2af989b1738954a9dcb2
dispatch: don't mangle abort messages from ImportErrors during commands

Previously, Mercurial assumed that the last word of the string
representation was the name of the moduled that was imported. This
assmption is incorrect, despite being true for the common case of an
exception raised by the Python VM.

For example, hgsubversion raises an ImportError with a helpful message
if the Subversion bindings were not found. The final word of this
message is not meaningful on its own, and is never the name of a
module.

This patch changes the output printed to be a simple stringification
of the exception instance. In most cases, this will be `abort: No
module named X!' rather than `abort: could not import module X!'.

No functionality change; all tests pass.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -105,8 +105,8 @@ def _runcatch(ui, args):
     except util.Abort, inst:
         ui.warn(_("abort: %s\n") % inst)
     except ImportError, inst:
+        ui.warn(_("abort: %s!\n") % inst)
         m = str(inst).split()[-1]
-        ui.warn(_("abort: could not import module %s!\n") % m)
         if m in "mpatch bdiff".split():
             ui.warn(_("(did you forget to compile extensions?)\n"))
         elif m in "zlib".split():


More information about the Mercurial-devel mailing list