From 1404412dba9a3ca4a3482e531ed9a1aa39493049 2015-10-26 14:28:26 From: Fairly Date: 2015-10-26 14:28:26 Subject: [PATCH] Set exit code on script errors. 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. --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index aa2d55f..6d0bbad 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2675,10 +2675,11 @@ class InteractiveShell(SingletonConfigurable): # 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 diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py index 4758c8d..1afbcb0 100644 --- a/IPython/core/shellapp.py +++ b/IPython/core/shellapp.py @@ -345,7 +345,8 @@ class InteractiveShellApp(Configurable): # 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 @@ -415,9 +416,8 @@ class InteractiveShellApp(Configurable): 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."""