Skip to content

Don't panic on metadata errors #100

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

Merged
merged 1 commit into from
Dec 28, 2020
Merged

Conversation

parasyte
Copy link

This expect() causes my cargo subcommand to panic when building a project with invalid Cargo.toml metadata. E.g. specifying a dependency that cannot be downloaded, or invalid TOML syntax.

Transforming the error into a string instead of panicking provides a much more readable error message, and potentially allows callers to handle the failure gracefully.

Before:

$ cargo n64 build --ipl3 ~/bin/CIC-NUS-6102.bin -- --package hello-ipl3font
    Building with cargo xbuild
thread 'main' panicked at 'cargo metadata invocation failed: CargoMetadata { stderr: "    Updating crates.io index\nerror: no matching package named `this-package-does-not-exist` found\nlocation searched: registry `https://github.com/rust-lang/crates.io-index`\nrequired by package `hello-ipl3font v0.1.0 (/Users/parasyte/projects/cargo-n64/examples/hello-ipl3font)`\n" }', /Users/parasyte/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-xbuild-0.6.3/src/lib.rs:145:31
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

After:

$ cargo n64 build --ipl3 ~/bin/CIC-NUS-6102.bin -- --package hello-ipl3font
    Building with cargo xbuild
error: xbuild error: cargo metadata invocation failed: Error during execution of `cargo metadata`:     Updating crates.io index
error: no matching package named `this-package-does-not-exist` found
location searched: registry `https://github.com/rust-lang/crates.io-index`
required by package `hello-ipl3font v0.1.0 (/Users/parasyte/projects/cargo-n64/examples/hello-ipl3font)`

@phil-opp
Copy link
Member

Thanks!

@phil-opp phil-opp merged commit a7f221e into rust-osdev:master Dec 28, 2020
phil-opp added a commit that referenced this pull request Dec 28, 2020
@phil-opp
Copy link
Member

Published as v0.6.4.

@parasyte parasyte deleted the dont-panic branch December 28, 2020 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants