Skip to content

Commit

Permalink
fix: Suppress subprocess traceback in case XONSH_SHOW_TRACEBACK=False…
Browse files Browse the repository at this point in the history
… and $RAISE_SUBPROC_ERROR=True (xonsh#5066)

* fix: Add and extra condition for print traceback from subprocess

* add news

* Apply pre-commit hooks

* Fix initial implementation using sys.exit

* Update pr-5066.rst

* Remove sys.exit

---------

Co-authored-by: Andy Kipp <[email protected]>
  • Loading branch information
xmnlab and anki-code committed Feb 27, 2023
1 parent b600c58 commit 0c713a0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
23 changes: 23 additions & 0 deletions news/pr-5066.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Suppress subprocess traceback on exception in case ``$XONSH_SHOW_TRACEBACK=False`` with ``$RAISE_SUBPROC_ERROR=True``.

**Security:**

* <news item>
3 changes: 2 additions & 1 deletion xonsh/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ def func_sig_ttin_ttou(n, f):
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)
Expand Down
15 changes: 9 additions & 6 deletions xonsh/procs/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,15 @@ def _raise_subproc_error(self):
"""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
Expand Down

0 comments on commit 0c713a0

Please sign in to comment.