-
Notifications
You must be signed in to change notification settings - Fork 5
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
Have non-zero exit code throw for consistency with ezspawn and execa #32
Comments
Could this be an opt-in behavior, maybe by exporting a separate function that does the throwing behavior?: import { x, xSafe } from 'tinyexec';
// This throws by default
try {
const result = await x('ls', ['-l']);
} catch (e) {
// handle error
}
// this will not throw
const result2 = await xSafe('ls', ['-l']); |
i've opened #34 to try tackle this in a breaking change, but im still unsure too @ericallam ben is right here that existing libraries all seem to throw when a non-zero exit occurs. so migrating to tinyexec is a pain (or ends up buggy because people forget to try/catch it) i'd like to avoid having a flag or two exports to switch this behaviour as its an easy way to go down the same bloated rabbit hole the other libraries went. we should decide if we want to throw, or if we don't, and it is what it is imo |
IMHO, we could probably use the option x('ls', ['-l'], { nothrow: true }) And make it default to |
I'd probably say that an exception should be thrown by default and released as I like the |
I quite like Maybe |
does anyone have a good example of why we wouldn't want to throw? it does mean you have to access the process through e.g. try {
await x('foo');
} catch (err) {
err.process; // a tinyexec process
} im not sure if there's much benefit to having a flag. you can achieve everything whichever way we do it, so i'd rather just go all in on whatever we decide on rather than making a new option |
@43081j in typescript this is a real pain. tinyexec would have to export the error type so you can do a |
i think you're right @benmccann maybe a flag is right after all, a currently it throws when a command fails catastrophically (e.g. if it just doesn't exist or node was unable to execute it at all), and non-zero exits just resolve like any other exit. so we may have bugs out in the wild where we've migrated and expected a throw but didn't get one |
Okay. |
added in 0.3.0 👍 |
I've opened #39 to discuss whether |
See https://github.com/sindresorhus/execa/blob/main/docs/errors.md#exit-code
And https://github.com/JS-DevTools/ez-spawn/blob/e7b51d8693be9b5ccedbe7eac7f8f7dd81b59ea2/lib/process-error.js#L9 / https://github.com/JS-DevTools/ez-spawn/blob/e7b51d8693be9b5ccedbe7eac7f8f7dd81b59ea2/lib/normalize-result.js#L31
The text was updated successfully, but these errors were encountered: