Skip to content

Commit

Permalink
[main] Move handling of unexpected exceptions to the top level.
Browse files Browse the repository at this point in the history
This should fix a bug where Ctrl-C in a sourced file wouldn't exit the
interpreter!  Similar to #395.

Should also fix #398 because the 'except' is now the whole program,
including main_loop.Interactive().
  • Loading branch information
Andy Chu committed Jul 6, 2019
1 parent 08b8b44 commit ae647d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 12 additions & 5 deletions bin/oil.py
Expand Up @@ -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:
Expand All @@ -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__':
Expand All @@ -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))
7 changes: 0 additions & 7 deletions osh/cmd_exec.py
Expand Up @@ -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)

Expand Down

0 comments on commit ae647d4

Please sign in to comment.