Mercurial > public > mercurial-scm > hg
comparison mercurial/hook.py @ 26692:8d1cfd77b64f
hook: raise a separate exception for when loading a hook fails
For easier catching.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Mon, 12 Oct 2015 18:49:23 -0700 |
parents | 56b2bcea2529 |
children | a930d66a04af |
comparison
equal
deleted
inserted
replaced
26691:23c0da28c034 | 26692:8d1cfd77b64f |
---|---|
33 obj = funcname | 33 obj = funcname |
34 funcname = obj.__module__ + "." + obj.__name__ | 34 funcname = obj.__module__ + "." + obj.__name__ |
35 else: | 35 else: |
36 d = funcname.rfind('.') | 36 d = funcname.rfind('.') |
37 if d == -1: | 37 if d == -1: |
38 raise error.Abort(_('%s hook is invalid ("%s" not in ' | 38 raise error.HookLoadError( |
39 'a module)') % (hname, funcname)) | 39 _('%s hook is invalid ("%s" not in a module)') |
40 % (hname, funcname)) | |
40 modname = funcname[:d] | 41 modname = funcname[:d] |
41 oldpaths = sys.path | 42 oldpaths = sys.path |
42 if util.mainfrozen(): | 43 if util.mainfrozen(): |
43 # binary installs require sys.path manipulation | 44 # binary installs require sys.path manipulation |
44 modpath, modfile = os.path.split(modname) | 45 modpath, modfile = os.path.split(modname) |
61 ui.traceback(e1) | 62 ui.traceback(e1) |
62 if ui.tracebackflag: | 63 if ui.tracebackflag: |
63 ui.warn(_('exception from second failed import ' | 64 ui.warn(_('exception from second failed import ' |
64 'attempt:\n')) | 65 'attempt:\n')) |
65 ui.traceback(e2) | 66 ui.traceback(e2) |
66 raise error.Abort(_('%s hook is invalid ' | 67 raise error.HookLoadError( |
67 '(import of "%s" failed)') % | 68 _('%s hook is invalid (import of "%s" failed)') % |
68 (hname, modname)) | 69 (hname, modname)) |
69 sys.path = oldpaths | 70 sys.path = oldpaths |
70 try: | 71 try: |
71 for p in funcname.split('.')[1:]: | 72 for p in funcname.split('.')[1:]: |
72 obj = getattr(obj, p) | 73 obj = getattr(obj, p) |
73 except AttributeError: | 74 except AttributeError: |
74 raise error.Abort(_('%s hook is invalid ' | 75 raise error.HookLoadError( |
75 '("%s" is not defined)') % | 76 _('%s hook is invalid ("%s" is not defined)') |
76 (hname, funcname)) | 77 % (hname, funcname)) |
77 if not callable(obj): | 78 if not callable(obj): |
78 raise error.Abort(_('%s hook is invalid ' | 79 raise error.HookLoadError( |
79 '("%s" is not callable)') % | 80 _('%s hook is invalid ("%s" is not callable)') |
80 (hname, funcname)) | 81 % (hname, funcname)) |
81 | 82 |
82 ui.note(_("calling hook %s: %s\n") % (hname, funcname)) | 83 ui.note(_("calling hook %s: %s\n") % (hname, funcname)) |
83 starttime = time.time() | 84 starttime = time.time() |
84 | 85 |
85 try: | 86 try: |