fix(path): clarify error message when path dependency has wrong package#16927
fix(path): clarify error message when path dependency has wrong package#16927raushan728 wants to merge 3 commits into
Conversation
|
r? @epage rustbot has assigned @epage. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
d5f8d89 to
603d687
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment has been minimized.
This comment has been minimized.
|
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. |
94076b6 to
fb20a60
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| ))), | ||
| None => { | ||
| let path = self.path.join("Cargo.toml"); | ||
| ops::read_package(&path, self.source_id, self.gctx)?; |
There was a problem hiding this comment.
Why are we doing a read_package here?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Why do we need the original IO error?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Sorry for pushing without confirmation went with Option<Option<Package>> approach as it felt the cleanest of the three options.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
This comment has been minimized.
This comment has been minimized.
142213e to
2fb9cd0
Compare
This comment has been minimized.
This comment has been minimized.
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
|
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. |
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.