Skip to content

fix(path): clarify error message when path dependency has wrong package#16927

Open
raushan728 wants to merge 3 commits into
rust-lang:masterfrom
raushan728:fix-15296
Open

fix(path): clarify error message when path dependency has wrong package#16927
raushan728 wants to merge 3 commits into
rust-lang:masterfrom
raushan728:fix-15296

Conversation

@raushan728
Copy link
Copy Markdown
Contributor

@raushan728 raushan728 commented Apr 22, 2026

View all comments

Fixes #15296

When a path dependency points to a directory with a wrong or missing package, Cargo now scans subdirectories and shows helpful hints about what packages exist nearby.

@rustbot rustbot added A-dependency-resolution Area: dependency resolution and the resolver S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 22, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 22, 2026

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

Copy link
Copy Markdown
Contributor

@epage epage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/cargo/core/resolver/errors.rs Outdated
Comment thread src/cargo/core/resolver/errors.rs Outdated
Comment thread src/cargo/core/resolver/errors.rs Outdated
Comment thread src/cargo/core/resolver/errors.rs Outdated
Comment thread src/cargo/sources/path.rs Outdated
Comment thread src/cargo/core/resolver/errors.rs Outdated
Comment thread src/cargo/core/resolver/errors.rs Outdated
Comment thread src/cargo/core/resolver/errors.rs Outdated
Comment thread tests/testsuite/path.rs Outdated
@rustbot rustbot added the A-registries Area: registries label Apr 23, 2026
@raushan728

This comment has been minimized.

@raushan728 raushan728 requested a review from epage April 23, 2026 12:47
Comment thread src/cargo/core/resolver/errors.rs
Comment thread src/cargo/core/resolver/errors.rs Outdated
Comment thread src/cargo/core/resolver/errors.rs Outdated
Comment thread src/cargo/core/registry.rs Outdated
@raushan728 raushan728 force-pushed the fix-15296 branch 3 times, most recently from d5f8d89 to 603d687 Compare April 24, 2026 06:58
@raushan728

This comment was marked as duplicate.

@raushan728 raushan728 requested a review from epage April 26, 2026 14:48
Comment thread src/cargo/core/resolver/errors.rs
Comment thread src/cargo/core/resolver/errors.rs Outdated
@rustbot

This comment has been minimized.

@raushan728
Copy link
Copy Markdown
Contributor Author

Since PathSource::query() now returns zero candidates for missing Cargo.toml instead of an IO error, some existing tests that expected the old error chain now show the resolver-level error message instead.

@raushan728 raushan728 force-pushed the fix-15296 branch 2 times, most recently from 94076b6 to fb20a60 Compare May 1, 2026 08:54
@raushan728 raushan728 requested a review from epage May 1, 2026 09:20
@rustbot

This comment has been minimized.

Comment thread src/cargo/sources/path.rs Outdated
Comment thread src/cargo/sources/path.rs
Comment thread tests/testsuite/path.rs
Comment thread tests/testsuite/path.rs
Comment thread src/cargo/core/resolver/errors.rs Outdated
@rustbot

This comment has been minimized.

@raushan728 raushan728 requested a review from epage May 10, 2026 11:29
Comment thread src/cargo/sources/path.rs Outdated
))),
None => {
let path = self.path.join("Cargo.toml");
ops::read_package(&path, self.source_id, self.gctx)?;
Copy link
Copy Markdown
Contributor

@epage epage May 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing a read_package here?

View changes since the review

Copy link
Copy Markdown
Contributor Author

@raushan728 raushan728 May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root_package() is called when Cargo.toml is missing but we still need the original IO error to propagate. Since read_package() now returns Ok(None) for missing files, we call ops::read_package directly to get the proper error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the original IO error?

Copy link
Copy Markdown
Contributor Author

@raushan728 raushan728 May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uninstall_cwd_no_project test expects the original "failed to read Cargo.toml" IO error when running cargo uninstall in a directory without a Cargo.toml. Without this call, root_package() would return the internal "no package found in source" error instead, which is a regression in the error message for users running cargo commands outside of a project directory.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root_package basically exists for cargo install / cargo uninstall. If I'm understanding correctly, we'd fallback to the error no package found in source. What if we replaced that text with failed to read {} in its own commit before this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for pushing without confirmation went with Option<Option<Package>> approach as it felt the cleanest of the three options.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note my "if". What I would expect is some discussion as to why we think keeping the internal error is important before moving forward, or at least when pushing the changes.

I would recommend communicating more as you contribute. For example, there have been several times where you've made decisions along the way and had the context for them but didn't post that with the PR update, requiring extra rounds of back and forth as I then need to get that context that wasn't included.

Copy link
Copy Markdown
Contributor Author

@raushan728 raushan728 May 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with Option<Option<>> as it was the simplest no new types needed, cleanly separates unloaded, missing, and loaded states.

For the "if" root_package is used by cargo uninstall outside a project, so some error is needed there. Used anyhow::format_err! instead of internal since a missing Cargo.toml is a user error not a Cargo bug, which avoids the bug report notes. Dropped Caused by: NOT_FOUND as you suggested.

Will post reasoning with each update going forward.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@epage I know you're busy no rush. I'm a student learning open source contribution and want to make sure this PR moves forward. Happy to make any changes you suggest. Please let me know when you get a chance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, English is not my first language and I sometimes miss the nuance in your comments, which has led to some misunderstandings. I appreciate your patience and will try to ask for clarification before making changes.

@rustbot

This comment has been minimized.

@raushan728 raushan728 force-pushed the fix-15296 branch 2 times, most recently from 142213e to 2fb9cd0 Compare May 12, 2026 06:53
@raushan728 raushan728 requested a review from epage May 12, 2026 07:23
@rustbot

This comment has been minimized.

@raushan728 raushan728 closed this May 14, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 14, 2026
@raushan728 raushan728 reopened this May 14, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 14, 2026
Track missing Cargo.toml state using Option<Option<Package>>, where
outer None means unloaded and inner None means loaded but missing.
This allows the resolver to produce standard diagnostics instead of
raw IO error chains.
- Scan subdirectories when a path dependency is missing or invalid.

- Show helpful hints suggesting packages that exist nearby.

Fixes rust-lang#15296
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 22, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-dependency-resolution Area: dependency resolution and the resolver A-registries Area: registries S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error message when wrong package found in a path dependency

3 participants