comparison mercurial/extensions.py @ 32724:ea1c2eb7abd3

extensions: catch uisetup and extsetup failures and don't let them break hg Otherwise users of the patience diff extension will be unable to run anything at all in hg 4.3 until they figure out what's broken.
author Augie Fackler <augie@google.com>
date Tue, 06 Jun 2017 10:09:48 -0400
parents de09138bf0f5
children 80a5d237a4ae
comparison
equal deleted inserted replaced
32723:b6384b3d4ebe 32724:ea1c2eb7abd3
165 return mod 165 return mod
166 166
167 def _runuisetup(name, ui): 167 def _runuisetup(name, ui):
168 uisetup = getattr(_extensions[name], 'uisetup', None) 168 uisetup = getattr(_extensions[name], 'uisetup', None)
169 if uisetup: 169 if uisetup:
170 uisetup(ui) 170 try:
171 uisetup(ui)
172 except Exception as inst:
173 ui.traceback()
174 msg = _forbytes(inst)
175 ui.warn(_("*** failed to set up extension %s: %s\n") % (name, msg))
176 return False
177 return True
171 178
172 def _runextsetup(name, ui): 179 def _runextsetup(name, ui):
173 extsetup = getattr(_extensions[name], 'extsetup', None) 180 extsetup = getattr(_extensions[name], 'extsetup', None)
174 if extsetup: 181 if extsetup:
175 try: 182 try:
176 extsetup(ui) 183 try:
177 except TypeError: 184 extsetup(ui)
178 if inspect.getargspec(extsetup).args: 185 except TypeError:
179 raise 186 if inspect.getargspec(extsetup).args:
180 extsetup() # old extsetup with no ui argument 187 raise
188 extsetup() # old extsetup with no ui argument
189 except Exception as inst:
190 ui.traceback()
191 msg = _forbytes(inst)
192 ui.warn(_("*** failed to set up extension %s: %s\n") % (name, msg))
193 return False
194 return True
181 195
182 def loadall(ui, whitelist=None): 196 def loadall(ui, whitelist=None):
183 result = ui.configitems("extensions") 197 result = ui.configitems("extensions")
184 if whitelist is not None: 198 if whitelist is not None:
185 result = [(k, v) for (k, v) in result if k in whitelist] 199 result = [(k, v) for (k, v) in result if k in whitelist]
201 % (name, msg)) 215 % (name, msg))
202 if isinstance(inst, error.Hint) and inst.hint: 216 if isinstance(inst, error.Hint) and inst.hint:
203 ui.warn(_("*** (%s)\n") % inst.hint) 217 ui.warn(_("*** (%s)\n") % inst.hint)
204 ui.traceback() 218 ui.traceback()
205 219
220 broken = set()
206 for name in _order[newindex:]: 221 for name in _order[newindex:]:
207 _runuisetup(name, ui) 222 if not _runuisetup(name, ui):
223 broken.add(name)
208 224
209 for name in _order[newindex:]: 225 for name in _order[newindex:]:
210 _runextsetup(name, ui) 226 if name in broken:
227 continue
228 if not _runextsetup(name, ui):
229 broken.add(name)
230
231 for name in broken:
232 _extensions[name] = None
211 233
212 # Call aftercallbacks that were never met. 234 # Call aftercallbacks that were never met.
213 for shortname in _aftercallbacks: 235 for shortname in _aftercallbacks:
214 if shortname in _extensions: 236 if shortname in _extensions:
215 continue 237 continue