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

cargo install exits with success code on partial failures #9180

Closed
horacimacias opened this issue Feb 17, 2021 · 7 comments · Fixed by #9185
Closed

cargo install exits with success code on partial failures #9180

horacimacias opened this issue Feb 17, 2021 · 7 comments · Fixed by #9185
Labels
C-bug Category: bug

Comments

@horacimacias
Copy link

Problem
cargo install exits with success code when installing a list of crates, even if some of them failed.
As a result, anybody running cargo install crate1 crate2 will get a false sense of success if one of the crates failed to install. For example Dockerfiles running such commands will not fail to build, which means the resulting container image does not contain all the crates one hopes to find installed, since cargo install still exited with success code.

Steps

  1. cargo install a list of crates where at least 1 fails and at least 1 succeeds. Right now I used cargo install --force cargo-sweep cargo-deny for example (as cargo-deny has issues installing without --locked; see Build failure due to bitvec dependency EmbarkStudios/cargo-deny#331 for details although the reason for failure is irrelevant to the issue reported here)
  2. Check the last command exit code. it should be non-zero but it is zero.

Possible Solution(s)
Perhaps it's better to succeed only if all requested crates were successfully installed.
As a side note, documentation for cargo install should be updated to reflect the behaviour, either current or future.

Notes

Output of cargo version:

cargo 1.49.0 (d00d64d 2020-12-05)
OSX using stable channel

@horacimacias horacimacias added the C-bug Category: bug label Feb 17, 2021
@ehuss
Copy link
Contributor

ehuss commented Feb 17, 2021

Hm, I just ran cargo install cargo-sweep cargo-deny and got this output:

~> cargo install cargo-sweep cargo-deny
...snip...

error: could not compile `bitvec`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: failed to compile `cargo-deny v0.8.6`, intermediate artifacts can be found at `/var/folders/rw/vx9xfxys6kjd5x1jw70pqg2c0000gn/T/cargo-installAvdwDX`

Caused by:
  build failed
     Summary Successfully installed cargo-sweep! Failed to install cargo-deny (see error(s) above).
warning: be sure to add `./bin` to your PATH to be able to run the installed binaries
error: some crates failed to install
~> echo $?
101

The important part is at the end error: some crates failed to install, and it exits with 101. Did you not get that error message? Can you show a reproduction where the exit code is nonzero?

@horacimacias
Copy link
Author

horacimacias commented Feb 17, 2021

thanks for looking at this.
It's weird; for me I'm getting a 0 status code.
I'm usually running fish shell v3.1.2 on OSX but I also tried bash on OSX and bash on linux; same results for me.

fish on OSX (it uses $status instead of $?):

Caused by:
  build failed
     Summary Successfully installed cargo-sweep! Failed to install cargo-deny (see error(s) above).
⋊> echo $status                                                                                                                                                                                                                                             
0

I also combined the command with "echo yes" and I see the echoed message:

cargo install cargo-sweep cargo-deny; and echo yes
....
Caused by:
  build failed
     Summary Successfully installed cargo-sweep! Failed to install cargo-deny (see error(s) above).
yes

we can ignore fish if that's not common enough.
I tried same thing in bash on OSX:

Caused by:
  build failed
     Ignored package `cargo-sweep v0.5.0` is already installed, use --force to override
     Summary Successfully installed cargo-sweep! Failed to install cargo-deny (see error(s) above).
computer:workspace hmacias$ echo $?
0
computer:workspace hmacias$ cargo version
cargo 1.49.0 (d00d64df9 2020-12-05)

and I also tried cargo install cargo-deny cargo-sweep && echo yes:

Caused by:
  build failed
     Ignored package `cargo-sweep v0.5.0` is already installed, use --force to override
     Summary Successfully installed cargo-sweep! Failed to install cargo-deny (see error(s) above).
yes

and finally cargo install cargo-deny cargo-sweep on bash's linux:

Caused by:
  build failed
     Ignored package `cargo-sweep v0.5.0` is already installed, use --force to override
     Summary Successfully installed cargo-sweep! Failed to install cargo-deny (see error(s) above).
[root@linpubab062 ~]# echo $?
0
[root@linpubab062 ~]# cargo version
cargo 1.45.0 (744bd1fbb 2020-06-15)
[root@linpubab062 ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

Running cargo install cargo-deny cargo-sweep && echo yes also printed 'yes'

I'm running out of ideas, everything I try seems to indicate the command is exiting with status code 0?

@horacimacias
Copy link
Author

tried deleting cargo-sweep in case this being already installed has any relation to things but no difference:

error: failed to compile `cargo-deny v0.8.6`, intermediate artifacts can be found at `/tmp/cargo-installT2EqzG`

Caused by:
  build failed
     Summary Successfully installed cargo-sweep! Failed to install cargo-deny (see error(s) above).
yes

@horacimacias
Copy link
Author

in case this is relevant, I see you're getting a error: some crates failed to install but I'm not.

We both see the Summary Successfully installed cargo-sweep! Failed to install cargo-deny (see error(s) above). but I'm not seeing the error: some crates failed to install anywhere 🤷

@horacimacias
Copy link
Author

last attempt using an official docker image, in case the problem is with my setup.
This is the Dockerfile:

FROM rust:1.50.0

RUN cargo install cargo-sweep cargo-deny && echo $?

docker build . runs successfully (I'd expect it to fail) and the $? prints 0:

Caused by:
  build failed
     Summary Successfully installed cargo-sweep! Failed to install cargo-deny (see error(s) above).
0
Removing intermediate container 11e8dbb05051
 ---> 16a0e8108c9a
Successfully built 16a0e8108c9a

@ehuss
Copy link
Contributor

ehuss commented Feb 18, 2021

My apologies, I see what is wrong. If the destination is in PATH, it is exiting prematurely. This line needs to change.

@horacimacias
Copy link
Author

thanks! let's see if this PR helps.

bors added a commit that referenced this issue Feb 19, 2021
Do not exit prematurely if anything failed installing.

#9180
ehuss pushed a commit to ehuss/cargo that referenced this issue Feb 22, 2021
Do not exit prematurely if anything failed installing.

rust-lang#9180
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants