Skip to content

"did not match any packages" error is not clear in a workspace #10782

Open
@ehuss

Description

@ehuss

Problem

The error: package ID specification `foo` did not match any packages message can be confusing in a workspace. If the package foo exists as a dependency in the workspace, but not within the "context" of the current package, then Cargo emits this rather opaque message.

Steps

The following test using cargo's testsuite illustrates an example:

#[cargo_test]
fn workspace_no_match() {
    // Checks the error message when a dependency in a workspace exists,
    // but is not part of the "current" package.
    Package::new("external", "0.1.0").publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
                [workspace]
                members = ["foo", "bar"]
                default-members = ["foo"]
            "#,
        )
        .file("foo/Cargo.toml", &basic_manifest("foo", "1.0.0"))
        .file("foo/src/lib.rs", "")
        .file(
            "bar/Cargo.toml",
            r#"
                [package]
                name = "bar"
                version = "0.1.0"

                [dependencies]
                external = "0.1"
            "#,
        )
        .file("bar/src/lib.rs", "")
        .build();

    // TODO: Improve this error message to provide more context.
    p.cargo("tree -i external")
        .with_stderr("error: package ID specification `external` did not match any packages")
        .run();
}

Possible Solution(s)

It would be nice if the error message provided a little more information. A rough example might be:

error: package ID specification `foo` did not match any packages
    Package `[email protected]` is part of the workspace dependency graph, but is not a dependency of the package `bar`.
    Try running `cargo tree --workspace -i foo` to scan the entire workspace.

This applies to all commands (like cargo build -p foo, etc.), so it might be a bit of work to customize it with suggestions and whatnot, but I think it would be wonderful if it did.

Notes

No response

Version

cargo 1.63.0-nightly (8d42b0e87 2022-06-17)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Error and warning messages generated by Cargo itself.A-workspacesArea: workspacesC-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions