diff --git a/mercurial/extensions.py b/mercurial/extensions.py --- a/mercurial/extensions.py +++ b/mercurial/extensions.py @@ -42,7 +42,12 @@ def loadpath(path, module_name): fd, fpath, desc = imp.find_module(f, [d]) return imp.load_module(module_name, fd, fpath, desc) else: - return imp.load_source(module_name, path) + try: + return imp.load_source(module_name, path) + except IOError, exc: + if not exc.filename: + exc.filename = path # python does not fill this + raise def load(ui, name, path): # unused ui argument kept for backwards compatibility diff --git a/mercurial/hook.py b/mercurial/hook.py --- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -169,7 +169,11 @@ def hook(ui, repo, name, throw=False, ** path = util.expandpath(path) if repo: path = os.path.join(repo.root, path) - mod = extensions.loadpath(path, 'hghook.%s' % hname) + try: + mod = extensions.loadpath(path, 'hghook.%s' % hname) + except Exception: + ui.write(_("loading %s hook failed:\n") % hname) + raise hookfn = getattr(mod, cmd) else: hookfn = cmd[7:].strip() diff --git a/tests/test-hook.t b/tests/test-hook.t --- a/tests/test-hook.t +++ b/tests/test-hook.t @@ -530,6 +530,20 @@ test python hook configured with python: nothing changed [1] + $ echo '[hooks]' > .hg/hgrc + $ echo "update.ne = python:`pwd`/nonexisting.py:testhook" >> .hg/hgrc + $ echo "pre-identify.npmd = python:`pwd`/:no_python_module_dir" >> .hg/hgrc + + $ hg up null + loading update.ne hook failed: + abort: No such file or directory: $TESTTMP/d/repo/nonexisting.py + [255] + + $ hg id + loading pre-identify.npmd hook failed: + abort: No module named repo! + [255] + $ cd ../../b make sure --traceback works on hook import failure