Skip to content

Misleading error message when crates.io is replace-with a local source #14697

Closed
@hoodmane

Description

@hoodmane

Problem

When using a local source via a replace-with in config.toml and there is a missing package, cargo build gives confusing errors saying that it searched crates-io for the package when it only looked in the local file system. The error it gives is identical to the error from an actually missing package:

error: no matching package named `<package name>` found
location searched: registry `crates-io`
required by package `example v0.1.0`

Possible Solution(s)

If you run cargo seach it gives much more specific information:

$ cargo search ahash
error: crates-io is replaced with non-remote-registry source dir /.../cargo-bug/vendor;
include `--registry crates-io` to use crates.io

It would be great if the original error included this "crates-io is replaced with non-remote-registry source" remark.

Steps

  1. Unpack this zip archive: cargo-bug.zip
  2. Run cargo build in root
  3. Get error:
    error: no matching package named `ahasha` found
    location searched: registry `crates-io`
    required by package `example v0.1.0 (/home/rchatham/Documents/programming/tmp/cargo-bug)`
    

As an alternative, instead of unpacking, make an empty folder, cd into it, make the following files and then do the following shell instructions:

Cargo.toml

[package]
name = "example"
version = "0.1.0"
edition = "2021"

[dependencies]
ahash = { version = "^0.8.9" }

.cargo/config.toml

[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"

Shell instructions

Then:

mkdir src
touch src/lib.rs
mkdir vendor
cargo build

Version

cargo 1.84.0-nightly (15fbd2f 2024-10-08)
release: 1.84.0-nightly
commit-hash: 15fbd2f
commit-date: 2024-10-08
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Ubuntu 22.4.0 (jammy) [64-bit]

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Error and warning messages generated by Cargo itself.A-source-replacementArea: [source] replacementC-bugCategory: bugE-easyExperience: EasyS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions