nabijaczleweli / cargo-update

A cargo subcommand for checking and applying updates to installed executables
MIT License
1.22k stars 42 forks source link

Panic when trying to update with no cargo binary installed #170

Closed gyscos closed 2 years ago

gyscos commented 2 years ago

When no binary has been cargo install'ed yet (including cargo-update), it panics:

thread 'main' panicked at 'index not found', src/ops/mod.rs:785:20

This can happen when cargo-update (and possibly others) are installed system-wide rather than using cargo itself.

This is using cargo-update ~0.8.0~ 8.0.0 on archlinux from the AUR: https://aur.archlinux.org/packages/cargo-update

At least the .crates.toml file exists (but is empty):

$ wc ~/.cargo/.crates.toml
0 0 0 /home/gyscos/.cargo/.crates.toml
nabijaczleweli commented 2 years ago
$ git show v0.8.0
tag v0.8.0
Tagger: nabijaczleweli <nabijaczleweli@gmail.com>
Date:   Sat Mar 25 20:40:49 2017 +0100
$ git show v0.8.0:src/ops/mod.rs | wc -l
389

huh?

gyscos commented 2 years ago

Ha ha nevermind turns out it was for another cargo command, cargo-install-update. Ugh I have a problem with names...

nabijaczleweli commented 2 years ago

no no, this crate does provide cargo install-update and cargo install-update-config, but 0.8.0 is both four years old and doesn't have a line 785 in the file you mentioned

gyscos commented 2 years ago

Ah yes it was 8.0.0, sorry for the typo. I suppose I got too used to sub-1 version numbers...

nabijaczleweli commented 2 years ago

ah, that makes more sense (and yeah, each time I bump this I mistype it at least twice, too)

nabijaczleweli commented 2 years ago

Okay, so you have a .crates.toml file (in $HOME/.cargo, presumably), but "index not found" probably points to the ["v1"] index going bad (this code is literally untouched since mid-2017, when it inherited the lack of error handling from its first incarnation in 2017. let's just say it's not written defensively nor well).

Would you mind posting the file here?

gyscos commented 2 years ago

I updated the top post; this file is empty on my machine. I'm not totally sure who created this file. Maybe cargo or rustup on first call? In any case if I remove the file entirely, the issues disappears (since cargo install-update doesn't even try to read it).

gyscos commented 2 years ago

Ah running cargo install --list does generate this empty file (as well as .crates2.json file, empty as well).

And sure enough it does open_rw which I suspects creates an empty file if it doesn't exist yet.

nabijaczleweli commented 2 years ago

Right. I explicitly check for no file but not for a lack of the v1 section. I'd say that this is a format violation on cargo's part, but :v

Would you mind trying the latest master branch (at least c57e0a2d7b0f20e1284c00ed9a1344e795c92a11)?

gyscos commented 2 years ago

The latest commit does indeed prevent this panic. Thanks!

nabijaczleweli commented 2 years ago

Ace, released in v8.1.2.