Skip to content

Don't panic on metadata errors - #100

Merged
phil-opp merged 1 commit into
rust-osdev:masterfrom
parasyte:dont-panic
Dec 28, 2020
Merged

Don't panic on metadata errors#100
phil-opp merged 1 commit into
rust-osdev:masterfrom
parasyte:dont-panic

Conversation

@parasyte

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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