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

unhelpful error message trying to uninstall ambiguous crate name #5006

Closed
matthiaskrgr opened this issue Feb 4, 2018 · 3 comments · Fixed by #5840
Closed

unhelpful error message trying to uninstall ambiguous crate name #5006

matthiaskrgr opened this issue Feb 4, 2018 · 3 comments · Fixed by #5840
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Feb 4, 2018

cargo 0.26.0-nightly (1d6dfea44 2018-01-26)
rustc 1.25.0-nightly (3d292b793 2018-02-03)

I have a rustfmt-nightly installed in $CARGO_HOME.
I tried to remove it:

cargo uninstall rustfmt-nightly 

error: There are multiple `rustfmt-nightly` packages in your project, and the specification `rustfmt-nightly` is ambiguous.
Please re-run this command with `-p <spec>` where `<spec>` is one of the following:
  rustfmt-nightly:0.3.4
  rustfmt-nightly:0.3.8

The error message is confusing, according to cargo help uninstall, -p is not even a valid option for uninstall

I tried a couple of things

cargo uninstall  -p "rustfmt-nightly:0.3.4" 
cargo  -p "rustfmt-nightly:0.3.4" uninstall
cargo uninstall rustfmt-nightly -p "rustfmt-nightly:0.3.4" 

but none of these worked.

EDIT:
Hmm, I found this in my $CARGO_HOME/.crates.toml

"rustfmt-nightly 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = ["git-fmt"]
"rustfmt-nightly 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = ["cargo-fmt", "git-rustfmt", "rustfmt", "rustfmt-format-diff"]
@alexcrichton alexcrichton added the A-diagnostics Area: Error and warning messages generated by Cargo itself. label Feb 4, 2018
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Feb 4, 2018

Hmm, I think the underlying problem is that rustfmt changed the name of its executable which might have confused cargo.
rust-lang/rustfmt@361a30b#diff-80398c5faae3c069e4e6aa2ed11b28c0
While upgrading from one version to another, cargo apparently did not remove the old binary properly so I ended up with orphaned executables, I guess.

EDIT: I can confirm via local testcase:

cargo installing

[package]
name = "cargo_test"
version = "0.1.0"

[dependencies]

[[bin]]
name = "test_1"
path = "src/main.rs"

, and then changing version and path

[package]
name = "cargo_test"
version = "0.2.0"

[dependencies]

[[bin]]
name = "test_2"
path = "src/main.rs"

and installing again will leave the old binary in place.

"cargo_test 0.1.0 (path+file:///tmp/cargo_test)" = ["test_1"]
"cargo_test 0.2.0 (path+file:///tmp/cargo_test)" = ["test_2"]

Uninstalling via
cargo uninstall cargo_test:0.1.0
cargo uninstall cargo_test:0.2.0
worked, so it seems the -p is simply wrong.

@seanmonstar
Copy link

To clarify, this issue is that the help text from cargo uninstall foo is incorrect if the spec is ambiguous. It suggests running cargo uninstall -p foo:1.2.3, when really you run cargo uninstall foo:1.2.3.

A fix to this issue would be removing the -p <spec> part of the help text.

ehuss added a commit to ehuss/cargo that referenced this issue Jul 31, 2018
The ambiguous spec error tells you to use `-p` which wasn't available for
this command.

Fixes rust-lang#5006
bors added a commit that referenced this issue Jul 31, 2018
Allow `-p` in `uninstall` to accommodate error messages.

The ambiguous spec error tells you to use `-p` which wasn't available for
this command.

Fixes #5006
@bors bors closed this as completed in #5840 Aug 1, 2018
@skyfaller
Copy link

I just ran into this bug on macOS Catalina 10.15.7 running the current cargo from homebrew:

> cargo install-update -a                                                                                                                                                
    Updating registry 'https://github.com/rust-lang/crates.io-index'

Package       Installed  Latest  Needs update
bk            v0.5.3     v0.5.3  No
cargo-update  v7.0.1     v7.0.1  No
dijo          v0.2.7     v0.2.7  No
kalk_cli      v0.5.4     v0.5.4  No
ncgopher      v0.2.0     v0.2.0  No
rtw           v2.3.0     v2.3.0  No
zee           v0.1.2     v0.1.2  No

No packages need updating.
Overall updated 0 packages.
> cargo uninstall kalk_cli                                                                                                                                               
error: There are multiple `kalk_cli` packages in your project, and the specification `kalk_cli` is ambiguous.
Please re-run this command with `-p <spec>` where `<spec>` is one of the following:
  kalk_cli:0.1.8
  kalk_cli:0.5.4
> cargo uninstall kalk_cli:0.1.8                                                                                                                                         
    Removing /Users/nelson/.cargo/bin/kalk_cli
> cargo uninstall kalk_cli:0.5.4                                                                                                                                         
    Removing /Users/nelson/.cargo/bin/kalk
> cargo --version                                                                                                                                                        
cargo 1.56.0
> brew info rust                                                                                                                                                         
rust: stable 1.56.0 (bottled), HEAD
Safe, concurrent, practical language
https://www.rust-lang.org/
/usr/local/Cellar/rust/1.56.0 (30,734 files, 763.3MB) *
  Poured from bottle on 2021-10-26 at 12:00:13
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/rust.rb
License: Apache-2.0 or MIT
==> Dependencies
Build: cmake ✘, ninja ✘, python@3.9 ✔
Required: libssh2 ✔, openssl@1.1 ✔, pkg-config ✔
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 28,991 (30 days), 93,440 (90 days), 289,660 (365 days)
install-on-request: 16,441 (30 days), 53,020 (90 days), 155,372 (365 days)
build-error: 0 (30 days)

This seems strange for a bug that was closed in 2018. I was able to use the workaround mentioned in this thread, but that help text doesn't look fixed to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants