Rustup: Warn, don't error, when adding an already installed target for the current toolchain

Created on 5 Nov 2018  路  7Comments  路  Source: rust-lang/rustup

$ rustup show
Default host: x86_64-unknown-freebsd

installed targets for active toolchain
--------------------------------------

x86_64-unknown-freebsd

active toolchain
----------------

stable-x86_64-unknown-freebsd (default)
rustc 1.30.0 (da5f414c2 2018-10-24)

$ rustup target add x86_64-unknown-freebsd
error: component 'rust-std' for target 'x86_64-unknown-freebsd' was automatically added because it is required for toolchain 'stable-x86_64-unknown-freebsd'

$ echo "$?"
1

This is not a particularly helpful behavior. When the user instructs rustup to install an already installed target, better to warn and exit with code zero (successful), rather than trigger a scary, unnecessary error.

Most helpful comment

BTW, something similar happens with other commands too:

$ rustup component add rust-docs
error: component 'rust-docs' for target 'x86_64-unknown-linux-gnu' was automatically added because it is required for toolchain 'nightly-x86_64-unknown-linux-gnu'
$ echo $?
1

Why is this an error? Maybe a deeper revision/refactoring would be needed in order to keep error handling, error/warn messages and RC consistant.

All 7 comments

Yeah, I just saw this, and it was surprising. It also makes it slightly harder to do what I want to do in automation, where idempotence would be handy.

I think it would be better if it's an info instead of a warning.

For reference, this is what happens when adding an uninstalled new target

$ rustup target add wasm32-unknown-emscripten
info: downloading component 'rust-std' for 'wasm32-unknown-emscripten'
 13.4 MiB /  13.4 MiB (100 %)   2.2 MiB/s ETA:   0 s                
info: installing component 'rust-std' for 'wasm32-unknown-emscripten'

How about this:

$ rustup target add wasm32-unknown-emscripten
info: component 'rust-std' for 'wasm32-unknown-emscripten' already installed
$ echo $?
0

warns generally alerts users and developers that something may not be well set up or may lead to unexpected results or even that some action should be made in order to get rid of it.

Reinstalling something already installed didn't fit this mindset, IMHO.
What do you think?

BTW, something similar happens with other commands too:

$ rustup component add rust-docs
error: component 'rust-docs' for target 'x86_64-unknown-linux-gnu' was automatically added because it is required for toolchain 'nightly-x86_64-unknown-linux-gnu'
$ echo $?
1

Why is this an error? Maybe a deeper revision/refactoring would be needed in order to keep error handling, error/warn messages and RC consistant.

I also ran into this:

$ rustup target add --toolchain=nightly x86_64-unknown-linux-gnu
error: component 'rust-std' for target 'x86_64-unknown-linux-gnu' was automatically added because it is required for toolchain 'nightly-x86_64-unknown-linux-gnu'

I have a Makefile which runs this for all targets I want to build for, including the current one. Was very upset to find out that this errors instead of simply printing that it's already installed.

@clarcharr it's fixed on the master https://github.com/rust-lang/rustup.rs/issues/441

Hi, I wanted to mention: Maybe since this is telling us we already have something we then tried to install again, the message could be friendlier? e.g.:

Already installed!

At first glance I thought I had done something wrong and that I didn't actually add the component I wanted to add.

Edit: (This is basically what @hbobenicio said. Sorry I didn't notice earlier.)

These days the messages are:

somniloquy(git)(馃馃彔)% rustup component add rustc                             
info: component 'rustc' for target 'x86_64-unknown-linux-gnu' is up to date
somniloquy(git)(馃馃彔)% rustup target add x86_64-unknown-linux-gnu             
info: component 'rust-std' for target 'x86_64-unknown-linux-gnu' is up to date
somniloquy(git)(馃馃彔)%                                                        

As such, I consider this resolved.

Was this page helpful?
0 / 5 - 0 ratings