rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.57k stars 2.38k forks source link

`cargo install` failing to parse crate metadata error should recommend removing `~/.cargo/.crates.toml` #2836

Open CryZe opened 8 years ago

CryZe commented 8 years ago

If your PC crashes while cargo is compiling something, it's pretty likely that your .cargo folder is corrupted after restarting your PC and you can't compile anything anymore. This happened 2 out of 2 times my PC crashed for me.

The errors you get with the corrupted .cargo folder look like this:

$ cargo install clippy --force
    Blocking waiting for file lock on the registry index
    Updating registry `https://github.com/rust-lang/crates.io-index`
 Downloading clippy v0.0.78
error: failed to parse crate metadata

To learn more, run the command again with --verbose.

Ideally cargo shouldn't ever leave its repository in a state where it can't recover from errors anymore.

alexcrichton commented 8 years ago

Oh this is actually not the metadata in .cargo but rather the metadata emitted by cargo install. Could you gist the contents of .cargo/.crates.toml?

CryZe commented 8 years ago

Looks like it's 855 NUL Bytes.

alexcrichton commented 8 years ago

Whoa that sounds... bad! I have no idea what we could do to cause it to just be a bunch of nul bytes...

alexcrichton commented 8 years ago

Unfortunately there's not a huge amount we can do about this corrupt metadata except complain about it. The error message could probably indicate what needs to get removed, but it loses all tracking information about installed binaries from crates.

cyplo commented 8 years ago

Would it be possible to write a test for that ? E.g. running cargo in debugger for N instructions and then killing it ?