New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement set -e
alternative
#5311
Comments
Indeed,
So we need additional setting e.g. |
set -e
alternative
JFYI. For this: set -e
ls nonono || true # false || true
echo "success" the xonsh equvalent for now is this: $RAISE_SUBPROC_ERROR = True
try:
ls nonono
except: # OR except subprocess.CalledProcessError:
pass
echo "success" |
You can create syntax sugar for this using macro call: import subprocess
def ignore_error(cmd):
"""Ignore failing of the command."""
try:
execx(cmd)
except subprocess.CalledProcessError:
pass
$RAISE_SUBPROC_ERROR = False
ignore_error!(echo 1 and (ls nonono or echo 2))
echo success
# success
$RAISE_SUBPROC_ERROR = True
ignore_error!(echo 1 and (ls nonono or echo 2))
echo success
# success |
I'm aware that I can do a try-except block to ignore errors, though that still doesn't help with the underlying problem of boolean logic being broken with subprocess return codes. |
I figured this out the case. What bash doing. In fact it implicitly overrides the execution of a logical expression and the execution of process. If we run In xonsh we have separation between process running and logical expression running. If we run In fact in this issue was requested an additional mode like RAISE_COMMAND_ERROR that will work for the whole logical expression. Current behavior: $RAISE_SUBPROC_ERROR=False
echo 1 and (ls no or echo 2)
# run logical: `echo 1`, `ls no`, `echo 2`.
__xonsh__.history[-1]
# rtn=0
echo 1 and (echo 2 or ls no)
# run logical: `echo 1`, `echo 2`.
__xonsh__.history[-1]
# rtn=0
$RAISE_SUBPROC_ERROR=True
echo 1 and (ls no or echo 2)
# run logical: `echo 1`, `ls no` (raise and stop).
__xonsh__.history[-1]
# rtn=2
echo 1 and (echo 2 or ls no)
# run logical: `echo 1`, `echo 2`.
__xonsh__.history[-1]
# rtn=0 |
xonfig
Expected Behavior
In bash, doing
cmd || true
will ignore any errors that the command generates ifset -e
is on. I would expect that the behavior is similar in Xonsh with$RAISE_SUBPROC_ERROR
, which is the equivalent setting.For example:
Current Behavior
A
subprocess.CalledProcessError
is called if any of the commands in the expression fail.Traceback (if applicable)
Steps to Reproduce
$RAISE_SUBPROC_ERROR = True
false || true
For community
⬇️ Please click the 👍 reaction instead of leaving a
+1
or 👍 commentThe text was updated successfully, but these errors were encountered: