diff --git a/bin/oil.py b/bin/oil.py index bb1e1237c1..4d6409d832 100755 --- a/bin/oil.py +++ b/bin/oil.py @@ -845,17 +845,24 @@ def AppBundleMain(argv): def main(argv): try: - sys.exit(AppBundleMain(argv)) + return AppBundleMain(argv) except NotImplementedError as e: raise except args.UsageError as e: #builtin.Help(['oil-usage'], util.GetResourceLoader()) log('oil: %s', e.msg) - sys.exit(2) + return 2 except RuntimeError as e: # NOTE: The Python interpreter can cause this, e.g. on stack overflow. log('FATAL: %r', e) - sys.exit(1) + return 1 + except KeyboardInterrupt: + print() + return 130 # 128 + 2 + except (IOError, OSError) as e: + # test this with prlimit --nproc=1 --pid=$$ + ui.Stderr('osh I/O error: %s', posix.strerror(e.errno)) + return 2 # dash gives status 2 finally: _tlog('Exiting main()') if _trace_path: @@ -864,7 +871,7 @@ def main(argv): # Called from Python-2.7.13/Modules/main.c. def _cpython_main_hook(): - main(sys.argv) + sys.exit(main(sys.argv)) if __name__ == '__main__': @@ -877,4 +884,4 @@ def _cpython_main_hook(): from opy import callgraph callgraph.Walk(main, sys.modules) else: - main(sys.argv) + sys.exit(main(sys.argv)) diff --git a/osh/cmd_exec.py b/osh/cmd_exec.py index b42700d1e5..9e600b40eb 100755 --- a/osh/cmd_exec.py +++ b/osh/cmd_exec.py @@ -1223,13 +1223,6 @@ def ExecuteAndCatch(self, node, fork_external=True): ui.PrettyPrintError(e, self.arena, prefix='fatal: ') is_fatal = True status = e.exit_status if e.exit_status is not None else 1 - except (IOError, OSError) as e: - # test this with prlimit --nproc=1 --pid=$$ - ui.Stderr('osh I/O error: %s', posix.strerror(e.errno)) - status = 2 # dash gives status 2 - except KeyboardInterrupt: - print() - status = 130 # 128 + 2 self.dumper.MaybeDump(status)