comparison mercurial/scmutil.py @ 45825:8f07f5a9c3de

worker: raise exception instead of calling sys.exit() with child's code When a worker process returns an error code, we would call `sys.exit()` with that exit code on the main process. The `SystemExit` exception would then get caught in `scmutil.callcatch()`, which would return that error code. The comment there says "Commands shouldn't sys.exit directly", which I agree with. This patch changes it so we raise a specific exception when a worker fails so we can catch instead. I think that means that `SystemExit` is now always an internal error. (I had earlier thought that this call to `sys.exit()` was from within the child process until Matt Harbison made me look again, so thanks for that!) Differential Revision: https://phab.mercurial-scm.org/D9287
author Martin von Zweigbergk <martinvonz@google.com>
date Sat, 07 Nov 2020 21:50:28 -0800
parents 508dfd1c18df
children 21733e8c924f
comparison
equal deleted inserted replaced
45824:9ac96b9fa76e 45825:8f07f5a9c3de
217 ui.error(_(b"abort: working directory revision cannot be specified\n")) 217 ui.error(_(b"abort: working directory revision cannot be specified\n"))
218 except error.Abort as inst: 218 except error.Abort as inst:
219 ui.error(_(b"abort: %s\n") % inst.message) 219 ui.error(_(b"abort: %s\n") % inst.message)
220 if inst.hint: 220 if inst.hint:
221 ui.error(_(b"(%s)\n") % inst.hint) 221 ui.error(_(b"(%s)\n") % inst.hint)
222 except error.WorkerError as inst:
223 # Don't print a message -- the worker already should have
224 return inst.status_code
222 except ImportError as inst: 225 except ImportError as inst:
223 ui.error(_(b"abort: %s!\n") % stringutil.forcebytestr(inst)) 226 ui.error(_(b"abort: %s!\n") % stringutil.forcebytestr(inst))
224 m = stringutil.forcebytestr(inst).split()[-1] 227 m = stringutil.forcebytestr(inst).split()[-1]
225 if m in b"mpatch bdiff".split(): 228 if m in b"mpatch bdiff".split():
226 ui.error(_(b"(did you forget to compile extensions?)\n")) 229 ui.error(_(b"(did you forget to compile extensions?)\n"))