WIP: wrote 3 tests about improving the error message in the path dependency#16138
WIP: wrote 3 tests about improving the error message in the path dependency#16138ibilalkayy wants to merge 4 commits intorust-lang:masterfrom
Conversation
2a4dc4d to
2bf90ff
Compare
2bf90ff to
4d041ea
Compare
This comment has been minimized.
This comment has been minimized.
|
@epage I noticed that there were 7 spaces missing on both lines. So I added them and the test got passed. I have squashed and pushed the code, but these spaces are not showing. Maybe it's a GitHub thing. There is a conflict that came after your changes. Should I resolve the error by keeping this function or remove it?
|
a12c57e to
9c538bb
Compare
src/cargo/core/resolver/errors.rs
Outdated
| use super::context::ResolverContext; | ||
| use super::types::{ConflictMap, ConflictReason}; | ||
|
|
||
| fn debug_source_path() { |
There was a problem hiding this comment.
If these are for local debugging purpose, please remove.
There was a problem hiding this comment.
This was showing where they are at in experimenting while they then work to change this to fit in
| edition = "2015" | ||
| authors = [] | ||
|
|
||
| [workspace] |
There was a problem hiding this comment.
Is [workspace] here essential? If not maybe we should remove.
src/cargo/core/resolver/errors.rs
Outdated
| let gctx = GlobalContext::default().unwrap(); | ||
| let sid = SourceId::for_path(path).unwrap(); | ||
|
|
||
| fn debug_source_path(msg: &mut String, path: &Path, gctx: &GlobalContext, sid: SourceId) { |
There was a problem hiding this comment.
These should go below where they are used so that the first item in the file is the starting point for reading it and going further down just adds more context
a9a8dc1 to
9695b25
Compare
| &mut msg, | ||
| "no matching package named `{}` found", | ||
| dep.package_name() | ||
| ); |
There was a problem hiding this comment.
This was moved from out of the else block, into it.
196d02a to
a025762
Compare
7e5a250 to
5ccd130
Compare
|
Hey @epage, I have now written my doubts and confusion in the comment that you can review it. Here is the code where I wrote comment: https://github.com/rust-lang/cargo/pull/16138/changes There is one functionality about the Plus I am not sure why the tests are passing locally but failing here with these two functions. |
5ccd130 to
754b8ad
Compare
…r the path dependencies
…for the path dependencies
754b8ad to
94cd203
Compare
| .with_status(101) | ||
| .with_stderr_data(str![[r#" | ||
| [ERROR] no matching package named `bar` found at `definitely_not_bar` | ||
| [NOTE] required by package `foo v0.5.0 ([ROOT]/foo)` |
There was a problem hiding this comment.
I'm assuming this test is failing. Tests should be atomic which includes tests passing. This should be showing the existing behavior so that the following commit then changes that behavior so we can see the new behavior.
|
|
||
| let global_context = match gctx { | ||
| Some(context) => context, | ||
| None => &GlobalContext::new(Shell::new(), PathBuf::new(), PathBuf::new()), |
There was a problem hiding this comment.
It seems suspicious for us to create global contexts on the fly
| &mut msg, | ||
| "no matching package named `{}` found at `{}`", | ||
| name.name, | ||
| dep.package_name() |
There was a problem hiding this comment.
Grammatically, this reads in an odd way.
"at" in a situation like this implies a location which would likely to be assumed to be a path but to say "package foo not found in package bar" is odd because they are both packages and a package cannot have packages inside of it.
I would instead recommend having a note naming the package that does exist at a specific path
| let root_package = | ||
| inspect_root_package(&mut msg, Path::new(&path), global_context, sid); | ||
|
|
||
| if let Some(name) = root_package { |
There was a problem hiding this comment.
what happens if a root package is not found?
| ) -> Option<RootPackageInfo> { | ||
| let mut ps = PathSource::new(path, sid, gctx); | ||
|
|
||
| ps.root_package().expect("failed to get the root"); |
There was a problem hiding this comment.
expects are an assert and should name the condition that is upholding this ("I expect foo to be true")
| .source_id() | ||
| .url() | ||
| .to_file_path() | ||
| .expect("[ERROR]: failed to get the path"); |
There was a problem hiding this comment.
expects are an assert and should name the condition that is upholding this ("I expect foo to be true")
|
|
||
| let pkg = ps | ||
| .read_package() | ||
| .expect("failed to read the package in root"); |
There was a problem hiding this comment.
Why are we getting the root package, throwing it away, then calling read_package?
| .read_package() | ||
| .expect("failed to read the package in root"); | ||
|
|
||
| let package_info = RootPackageInfo { |
There was a problem hiding this comment.
Why do we need a struct for this?
| let _ = writeln!( | ||
| &mut msg, | ||
| "help: package `{}` exists at `{}`", | ||
| name.name, name.name |
There was a problem hiding this comment.
The at is giving the package name
| let _ = writeln!( | ||
| &mut msg, | ||
| "help: package `{}` exists at `{}`", | ||
| name.name, name.name |
| _path: PathBuf, | ||
| } | ||
|
|
||
| fn inspect_recursive_packages( |
There was a problem hiding this comment.
this name doesn't say what it is doing
| msg: &mut String, | ||
| path: &Path, | ||
| gctx: &GlobalContext, | ||
| sid: SourceId, | ||
| ) -> Option<RootPackageInfo> { |
There was a problem hiding this comment.
A bit unusual to have a function like this also modify msg
| } | ||
|
|
||
| fn inspect_recursive_packages( | ||
| msg: &mut String, |
There was a problem hiding this comment.
A bit unusual to have a function like this also modify msg
| } else if let Some(name) = recursive_packages { | ||
| let _ = writeln!( | ||
| &mut msg, | ||
| "no matching package named `{}` found at `{}`", |
There was a problem hiding this comment.
We sure are repeating this a lot
| let manifest = pkg.manifest_path(); | ||
| let pkg_dir = manifest | ||
| .parent() | ||
| .expect("failed to take the parent path") |
| // } else { | ||
| // let list = rps.list_files(&pkg).unwrap(); | ||
| // println!("{:?}", list); |
| let package_info = RecursivePackageInfo { | ||
| name: pkg.name().to_string(), | ||
| _path: pkg_dir, | ||
| }; |
What does this PR try to resolve?
This PR is trying to improve the error message when the wrong package is found in the path dependency. Currently the PR started from the tests.
How to test and review this PR?
There are 3 tests added that cover each case that is brought up in this issue.
invalid_package_name_in_path()definitely_not_barexists in thecrates/barand it goes to thecrates/barto find that it is not present there and it gives the error.invalid_package_in_subdirectory()definitely_not_barexists in thecrates/barand after going there, it does not find it. Then it goes more deeper in thedefinitely_not_barto find that the manifest file exists there and give use the helpful message.invalid_manifest_in_path()definitely_not_barexists in thecrates/barbut after going there, it finds that there are other two packages butdefinitely_not_baris not present and it gives the message.