mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
fix: Suppress subprocess traceback in case XONSH_SHOW_TRACEBACK=False and $RAISE_SUBPROC_ERROR=True (#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 <anki-code@users.noreply.github.com>
This commit is contained in:
parent
b600c58766
commit
0c713a0c31
3 changed files with 34 additions and 7 deletions
23
news/pr-5066.rst
Normal file
23
news/pr-5066.rst
Normal file
|
@ -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>
|
|
@ -558,6 +558,7 @@ def main_xonsh(args):
|
|||
if err_type is SystemExit:
|
||||
raise err
|
||||
else:
|
||||
if XSH.env.get("XONSH_SHOW_TRACEBACK"):
|
||||
traceback.print_exception(*exc_info)
|
||||
exit_code = 1
|
||||
events.on_exit.fire()
|
||||
|
|
|
@ -594,7 +594,10 @@ 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"):
|
||||
|
||||
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:
|
||||
|
|
Loading…
Add table
Reference in a new issue