Skip to content

Commit

Permalink
Set exit code on script errors.
Browse files Browse the repository at this point in the history
Only handle the issue related to .py scripts.

1. interactiveshell: The method safe_execfile is not totally safe now. Errors of user scripts  are raised to a higher level, where we can decide what to do.

2. execution: The %run magic catches exceptions from safe_execfile.

3. shellapp: The _run_cmd_line_code method catches exceptions from safe_execfile and sets the right exit status.

Partial-revert:

1. Change execution.py back.

2. Revert some changes in safe_execfile, then modify the excetion
handling logic.
  • Loading branch information
Fairly authored and minrk committed Oct 26, 2015
1 parent ee98b5f commit 1404412
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions IPython/core/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -2675,10 +2675,11 @@ def safe_execfile(self, fname, *where, **kw):
# 0
# For other exit status, we show the exception unless
# explicitly silenced, but only in short form.
if kw['raise_exceptions']:
raise
if status.code and not kw['exit_ignore']:
self.showtraceback(exception_only=True)
if status.code:
if kw['raise_exceptions']:
raise
if not kw['exit_ignore']:
self.showtraceback(exception_only=True)
except:
if kw['raise_exceptions']:
raise
Expand Down
8 changes: 4 additions & 4 deletions IPython/core/shellapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ def _exec_file(self, fname, shell_futures=False):
# default to python, even without extension
self.shell.safe_execfile(full_filename,
self.shell.user_ns,
shell_futures=shell_futures)
shell_futures=shell_futures,
raise_exceptions=True)
finally:
sys.argv = save_argv

Expand Down Expand Up @@ -415,9 +416,8 @@ def _run_cmd_line_code(self):
try:
self._exec_file(fname, shell_futures=True)
except:
self.log.warn("Error in executing file in user namespace: %s" %
fname)
self.shell.showtraceback()
self.shell.showtraceback(tb_offset=4)
self.exit(1)

def _run_module(self):
"""Run module specified at the command-line."""
Expand Down

0 comments on commit 1404412

Please sign in to comment.