Comments (5)
Indeed, $RAISE_SUBPROC_ERROR
is to raise error in any case when any command fails but set -e
treat the line as whole:
Exit immediately if a pipeline (see Pipelines), which may consist of a single simple command (see Simple Commands), a list (see Lists of Commands), or a compound command (see Compound Commands) returns a non-zero status.
So we need additional setting e.g. $XONSH_RAISE_SUBPROC_PIPELINE_ERROR
to do the same as bash. PR is welcome!
from xonsh.
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"
from xonsh.
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
from xonsh.
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.
from xonsh.
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 echo 1 and ls nonono
the result of this logical will be treated as "return code" and if it's not 0 and set -e
the error will be raised.
In xonsh we have separation between process running and logical expression running. If we run echo 1 and ls nonono
we have 2 separate processes and logical expression and RAISE_SUBPROC_ERROR will work on process level.
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
from xonsh.
Related Issues (20)
- Refactoring: soft split xonsh into components
- Refactoring: commands cache
- Xonsh immediately crashes when started, ujson attribute error HOT 2
- Reduce loading colors in non interactive command
- Refactoring: split `tools.py` into libs
- INVERT_ prompt color prefix does nothing HOT 1
- {user} in $PROMPT inaccurate if the user is root HOT 1
- $SHELL wrongly set; messes with tmux HOT 4
- Test failure building for NixOS HOT 1
- Refactoring: xontribs HOT 3
- No good way to get the last return code in a script HOT 2
- Implement `exit N` HOT 3
- current main: callable alias completion `Exception sequence item 0: expected str instance, FuncAlias found`
- Sometimes I see lag in first xonsh (or any python app?) run in new ssh session HOT 3
- Edge case: Shadowing xonsh in case of running script with shebang in virtual env
- Wrong path resolution in subprocess HOT 5
- Run tests: `fixture 'xession' not found use 'pytest --fixtures [testpath]' for help on them.` HOT 1
- conda and mamba: `DeprecationWarning: Use xonsh.lib.lazyasd instead of xonsh.lazyasd.` HOT 1
- What is changed after releasing new resolver? HOT 2
- Windows: Comapre typing speed: xonsh 0.16.0 vs 0.18.2 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xonsh.