comparison mercurial/dispatch.py @ 29761:39149b6036e6

dispatch: split global error handling out so it can be reused We may want a similar error handling at worker.py. This patch extracts the error handling logic to "callcatch" so it can be reused.
author Jun Wu <quark@fb.com>
date Tue, 09 Aug 2016 16:45:28 +0100
parents 12769703d4ba
children 2654a0aac80d
comparison
equal deleted inserted replaced
29760:3df9f780c90e 29761:39149b6036e6
148 if num: 148 if num:
149 signal.signal(num, catchterm) 149 signal.signal(num, catchterm)
150 except ValueError: 150 except ValueError:
151 pass # happens if called in a thread 151 pass # happens if called in a thread
152 152
153 try: 153 def _runcatchfunc():
154 try: 154 try:
155 debugger = 'pdb' 155 debugger = 'pdb'
156 debugtrace = { 156 debugtrace = {
157 'pdb' : pdb.set_trace 157 'pdb' : pdb.set_trace
158 } 158 }
210 traceback.print_exc() 210 traceback.print_exc()
211 debugmortem[debugger](sys.exc_info()[2]) 211 debugmortem[debugger](sys.exc_info()[2])
212 ui.traceback() 212 ui.traceback()
213 raise 213 raise
214 214
215 return callcatch(ui, _runcatchfunc)
216
217 def callcatch(ui, func):
218 """call func() with global exception handling
219
220 return func() if no exception happens. otherwise do some error handling
221 and return an exit code accordingly.
222 """
223 try:
224 return func()
215 # Global exception handling, alphabetically 225 # Global exception handling, alphabetically
216 # Mercurial-specific first, followed by built-in and library exceptions 226 # Mercurial-specific first, followed by built-in and library exceptions
217 except error.AmbiguousCommand as inst: 227 except error.AmbiguousCommand as inst:
218 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % 228 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
219 (inst.args[0], " ".join(inst.args[1]))) 229 (inst.args[0], " ".join(inst.args[1])))