Skip to content
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

Shell execution continues after failed command #11084

Closed
wollowizard opened this issue May 15, 2024 · 1 comment · Fixed by #11092
Closed

Shell execution continues after failed command #11084

wollowizard opened this issue May 15, 2024 · 1 comment · Fixed by #11092
Assignees
Labels
bug Something isn't working shell Something to do with Bun as a shell

Comments

@wollowizard
Copy link

What version of Bun is running?

1.1.8+89d25807f

What platform is your computer?

Darwin 23.3.0 arm64 arm

What steps can reproduce the bug?

in Bun shell, I believe there's an issue with some commands, where even if they fail, they allow execution of subsequent instructions. Example:

import {$} from "bun";
try {
    await $`cd non-existent-directory && echo " This should not be printed?"`
}catch (e) {
    console.log("error");
}

the output is: cd: not a directory: non-existent-directory This should not be printed?

However this does not happen with all commands, for example

import {$} from "bun";
try {
    await $`cat non-existent-directory && echo " This should not be printed?"`
}catch (e) {
    console.log("error");
}

prints:

cat: non-existent-directory: No such file or directory
error

Finally, if the instructions are on 2 lines, then the previous return code is always ignored (which is also the case in bash):

import {$} from "bun";
try {
    await $`cat non-existent-directory 
    echo " This should not be printed?"`
}catch (e) {
    console.log("error");
}

but it would be nice to have a behavior similar to set -euo pipefail (maybe by default or at least opt-in).

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

@wollowizard wollowizard added the bug Something isn't working label May 15, 2024
@zackradisic
Copy link
Contributor

This looks like a bug where cd is returning the wrong exit code, otherwise && symbol works:

bun -e 'await Bun.$`ls lskdjfksjdflksdf && echo cant see this`.throws(false)'

>> ls: lskdjfksjdflksdf: No such file or directory

As for set -euo pipefail we should definitely add this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working shell Something to do with Bun as a shell
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants