Skip to content
Snippets Groups Projects
Commit 1b2b727a885f authored by Simon Heimberg's avatar Simon Heimberg
Browse files

hooks: print out more information when loading a python hook fails

When loading a python hook with file syntax fails, there is no
information that this happened while loading a hook. When the python
file does not exist even the file name is not printed. (Only that a
file is missing.)

This patch adds this information and a test for loading a non existing file and
a directory not being a python module.
parent 01c1ee4bd1dd
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,12 @@
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
......
......@@ -169,7 +169,11 @@
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()
......
......@@ -530,6 +530,20 @@
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment