comparison mercurial/hook.py @ 28109:b892e424f88c

hook: don't crash on syntax errors in python hooks We had some real-world cases where syntax errors in Python hooks would crash the whole process and leave it in an indeterminate state. Handle those better.
author Siddharth Agarwal <sid0@fb.com>
date Fri, 12 Feb 2016 14:50:10 -0800
parents 2a71d9483199
children 44bd37af54e5
comparison
equal deleted inserted replaced
28108:2a71d9483199 28109:b892e424f88c
47 sys.path = sys.path[:] + [modpath] 47 sys.path = sys.path[:] + [modpath]
48 modname = modfile 48 modname = modfile
49 with demandimport.deactivated(): 49 with demandimport.deactivated():
50 try: 50 try:
51 obj = __import__(modname) 51 obj = __import__(modname)
52 except ImportError: 52 except (ImportError, SyntaxError):
53 e1 = sys.exc_info() 53 e1 = sys.exc_info()
54 try: 54 try:
55 # extensions are loaded with hgext_ prefix 55 # extensions are loaded with hgext_ prefix
56 obj = __import__("hgext_%s" % modname) 56 obj = __import__("hgext_%s" % modname)
57 except ImportError: 57 except (ImportError, SyntaxError):
58 e2 = sys.exc_info() 58 e2 = sys.exc_info()
59 if ui.tracebackflag: 59 if ui.tracebackflag:
60 ui.warn(_('exception from first failed import ' 60 ui.warn(_('exception from first failed import '
61 'attempt:\n')) 61 'attempt:\n'))
62 ui.traceback(e1) 62 ui.traceback(e1)