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

Enhance error output on missing Cargo.lock #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chrysn
Copy link
Contributor

@chrysn chrysn commented Dec 2, 2020

This changes the previously generic error ("File not found") to produce this when a library crate uses built's set_dependencies gets built:

error: failed to run custom build command for `leafcrate v0.1.0 (/tmp/leafcrate)`

Caused by:
  process didn't exit successfully: `/tmp/leafcrate/target/debug/build/leafcrate-1c09147a939b59c4/build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'Failed to acquire build-time information: Custom { kind: NotFound, error: "No Cargo.lock file found, see set_dependencies documentation" }', build.rs:9:10
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Contributes-To: #32

@lukaslueg
Copy link
Owner

Thanks for the PR!

I think there is a problem here because the current code maps any kind of error and replaces the message with one that specifically refers to "no found". We could still improve the situation by printing a longer message to stderr, which Cargo will replay. Something to the tune of

fs::File::open(manifest_location.join("Cargo.lock"))
    .map_err(|e| {
            eprintln!("Failed to open Cargo.lock. This information is only available for top-level packages. See the documentation for `built::Options::set_dependencies`.");
            e
        })?
        .read_to_string(&mut lock_buf)?;

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