Comments (13)
If your script returns 0, it was a success. If it returns nonzero, it failed.
If you don't want your script to fail fast, you can capture each of the return codes from the commands within your script and coalesce/convert as desired. The important thing to remember is that scripty (as is true of shell programming in general) has no knowledge of the commands that occur within the script. The contract that shell programs rely on is:
- respect STDIN, STDOUT, and STDERR
- return 0 means success
- return nonzero means failure
Scripty can only be aware of the exit code of the command it runs. So if your script returns 0, scripty sees it as a success; return nonzero: failure. set -e
is commonly (no judgement here) an easy way out of dealing with exit codes. But all that does is ensures the script returns with the same code as the first non-zero command.
from scripty.
Woah, if that's true, that is definitely a bug.
Could you post a project that reproduces the problem? Or to the repo's example project? Or add a failing test?
from scripty.
Yeah, I'll try to get something going today as a proof of concept.
from scripty.
Got a repo ready for you, along with lengthy explanation of my observations in the README.md
file: https://gitlab.com/Greduan/scripty-erroneous-error-handling-pof
from scripty.
Thanks.
This is an area I stupidly punted on because I didn't know how to reduce multiple exit codes to a single one.
Maybe I should just add them all together.
from scripty.
Not sure what the internals are so I can't really suggest any real solutions, but my use case is simply for it to exit with an error code that isn't 0 whenever one of the commands fails, that's all.
from scripty.
I'm having the same problems, and for my team's use cases it's enough to return immediately on the first non-zero exit code. So if you have two commands being run in the same scripty script, if the first one returns non-zero, it's fine to exit there with that status.
from scripty.
@mike-engel I believe one workaround is the following:
npm run yourcommand || exit 1 # $? if you want to preserve the command's exit status
||
is the opposite of &&
, it triggers if the exit code is not 0, then you just make the script exit.
from scripty.
Root cause: the fact that scripts/test
contains invocations of npm run …
was probably a red herring, because it seemed like the sort of thing that scripty should know about and handle. In truth, because scripts/test
was a custom script, scritpy doesn't have any visibility into what's inside of it. So the fact is that because the shell script above will exit 0 because of echo
, it will also exit 0 when spawned by scripty.
By adding the set -e
flag to the script, it'll fail fast and the script will exit non-zero, scripty will see it, and will also fail non-zero.
If you wanted to get this functionality out of the box, you could have scoped one
and two
underneath a directory named scripts/test
and then, when running npm test
, scripty would run both test:one
and test:two
and exit non-zero if either failed (with the exit code of the last failure)
from scripty.
I submitted a PR to demonstrate: https://gitlab.com/Greduan/scripty-erroneous-error-handling-pof/merge_requests/1
from scripty.
@searls is that for @mike-engel or me? Or both?
In any case, set -e
would work for fail-fast.
Though what if I don't want it fail-fast? What if I want to run all the tests just to see if everything else passes and not have to run the CI again just to see that.
The reason I'm doing npm run one
and npm run two
inside of scripts/test/index
is because I do not want to run all the scripts that are under scripts/test/
, in my real example it would be that I don't want to run test:clean
and test:knexreset
, as those are used inside the other ones that do need them.
Though I guess I could just do clean:clean
and clean:knexreset
or something like that.
from scripty.
The comment was directed at the broader issue, I suppose.
If you don't want to fail fast, then you'd need to find a scripting approach to accomplish it within the script. Since sh
is going to return 0, there's nothing scripty can do to enforce a failure.
from scripty.
Thought it'd be something like this, I also couldn't come up with a way to keep track of the escape codes of the innards of a shell script. I'll have to be cleverer about the script structure.
Thanks for your time. :)
from scripty.
Related Issues (20)
- The scripty.path config is not work. HOT 2
- Bug while sharing scripts via node modules HOT 3
- Update dependency to remove vulnerability. HOT 2
- Scripts Path Not Read With Yarn 3
- PNPM Support HOT 3
- monorepo single config HOT 2
- In MAC, may be unenforceable directory, how can do before running scripts, automatically run chmod + x scripts/path/to/my/script HOT 7
- scripty ERR! It seems you may be running scripty from the command-line directly HOT 1
- pnpm build error, unknown options: 'commitizen_path', 'scripty_path', 'scripty_windowsPath' #
- Scripts fail with Node.js v >=18 HOT 3
- Revive builtIn scripts resolver HOT 2
- Batch scripts skip directories HOT 1
- Sharable scripts via a npm package HOT 3
- Default to silent mode; allow verbose option HOT 1
- multiple script locations HOT 6
- Allow directly running using "scripty <target>" HOT 8
- npm proposal for proxying "npm run"
- Script name and content is always printed HOT 3
- Issue while running scripty on windows10 HOT 7
- Options won't work with npm >= 7 HOT 7
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 scripty.