diff --git a/news/pr-5066.rst b/news/pr-5066.rst new file mode 100644 index 000000000..135d2fd3c --- /dev/null +++ b/news/pr-5066.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Suppress subprocess traceback on exception in case ``$XONSH_SHOW_TRACEBACK=False`` with ``$RAISE_SUBPROC_ERROR=True``. + +**Security:** + +* diff --git a/xonsh/main.py b/xonsh/main.py index 838b1fe91..89d111a30 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -558,7 +558,8 @@ def main_xonsh(args): if err_type is SystemExit: raise err else: - traceback.print_exception(*exc_info) + if XSH.env.get("XONSH_SHOW_TRACEBACK"): + traceback.print_exception(*exc_info) exit_code = 1 events.on_exit.fire() postmain(args) diff --git a/xonsh/procs/pipelines.py b/xonsh/procs/pipelines.py index 623b3a8f7..16128e58b 100644 --- a/xonsh/procs/pipelines.py +++ b/xonsh/procs/pipelines.py @@ -594,12 +594,15 @@ class CommandPipeline: """Raises a subprocess error, if we are supposed to.""" spec = self.spec rtn = self.returncode - if rtn is not None and rtn != 0 and XSH.env.get("RAISE_SUBPROC_ERROR"): - try: - raise subprocess.CalledProcessError(rtn, spec.args, output=self.output) - finally: - # this is need to get a working terminal in interactive mode - self._return_terminal() + + if rtn is None or rtn == 0 or not XSH.env.get("RAISE_SUBPROC_ERROR"): + return + + try: + raise subprocess.CalledProcessError(rtn, spec.args, output=self.output) + finally: + # this is need to get a working terminal in interactive mode + self._return_terminal() # # Properties