Skip to content

WIP: wrote 3 tests about improving the error message in the path dependency#16138

Draft
ibilalkayy wants to merge 4 commits intorust-lang:masterfrom
ibilalkayy:path_dependency_msg_improvement
Draft

WIP: wrote 3 tests about improving the error message in the path dependency#16138
ibilalkayy wants to merge 4 commits intorust-lang:masterfrom
ibilalkayy:path_dependency_msg_improvement

Conversation

@ibilalkayy
Copy link
Contributor

@ibilalkayy ibilalkayy commented Oct 22, 2025

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()

    • It reads the main manifest file to find that the definitely_not_bar exists in the crates/bar and it goes to the crates/bar to find that it is not present there and it gives the error.
  • invalid_package_in_subdirectory()

    • It reads the main manifest file to find that the definitely_not_bar exists in the crates/bar and after going there, it does not find it. Then it goes more deeper in the definitely_not_bar to find that the manifest file exists there and give use the helpful message.
  • invalid_manifest_in_path()

    • It reads the main manifest file to find that definitely_not_bar exists in the crates/bar but after going there, it finds that there are other two packages but definitely_not_bar is not present and it gives the message.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 22, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 22, 2025

r? @ehuss

rustbot has assigned @ehuss.
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

@epage epage marked this pull request as draft October 22, 2025 14:20
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 22, 2025
@epage epage changed the title wrote 3 tests about improving the error message in the path dependency WIP: wrote 3 tests about improving the error message in the path dependency Oct 22, 2025
@ibilalkayy ibilalkayy force-pushed the path_dependency_msg_improvement branch from 2a4dc4d to 2bf90ff Compare October 29, 2025 14:15
@ibilalkayy ibilalkayy force-pushed the path_dependency_msg_improvement branch from 2bf90ff to 4d041ea Compare October 29, 2025 16:29
@rustbot rustbot added A-cli-help Area: built-in command-line help A-completions Area: shell completions A-documenting-cargo-itself Area: Cargo's documentation A-timings Area: timings Command-test labels Oct 29, 2025
@rustbot

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. label Oct 29, 2025
@ibilalkayy
Copy link
Contributor Author

ibilalkayy commented Oct 29, 2025

@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?

function get_codegen_section_x(sections) {...}

@ibilalkayy ibilalkayy force-pushed the path_dependency_msg_improvement branch 3 times, most recently from a12c57e to 9c538bb Compare November 5, 2025 17:00
@rustbot rustbot added the A-dependency-resolution Area: dependency resolution and the resolver label Nov 26, 2025
use super::context::ResolverContext;
use super::types::{ConflictMap, ConflictReason};

fn debug_source_path() {
Copy link
Member

Choose a reason for hiding this comment

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

If these are for local debugging purpose, please remove.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was showing where they are at in experimenting while they then work to change this to fit in

edition = "2015"
authors = []

[workspace]
Copy link
Member

Choose a reason for hiding this comment

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

Is [workspace] here essential? If not maybe we should remove.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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

@ibilalkayy ibilalkayy force-pushed the path_dependency_msg_improvement branch from a9a8dc1 to 9695b25 Compare January 13, 2026 07:23
&mut msg,
"no matching package named `{}` found",
dep.package_name()
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This was moved from out of the else block, into it.

@ibilalkayy ibilalkayy force-pushed the path_dependency_msg_improvement branch 2 times, most recently from 196d02a to a025762 Compare February 18, 2026 17:23
@ibilalkayy ibilalkayy force-pushed the path_dependency_msg_improvement branch 2 times, most recently from 7e5a250 to 5ccd130 Compare March 5, 2026 22:12
@ibilalkayy
Copy link
Contributor Author

ibilalkayy commented Mar 5, 2026

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 invalid_manifest_in_path remaining that needs to be written and called out

Plus I am not sure why the tests are passing locally but failing here with these two functions.

@ibilalkayy ibilalkayy requested a review from epage March 5, 2026 23:22
@ibilalkayy ibilalkayy force-pushed the path_dependency_msg_improvement branch from 5ccd130 to 754b8ad Compare March 6, 2026 12:09
@ibilalkayy ibilalkayy force-pushed the path_dependency_msg_improvement branch from 754b8ad to 94cd203 Compare March 6, 2026 18:54
.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)`
Copy link
Contributor

Choose a reason for hiding this comment

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

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()),
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems suspicious for us to create global contexts on the fly

Comment on lines +414 to +417
&mut msg,
"no matching package named `{}` found at `{}`",
name.name,
dep.package_name()
Copy link
Contributor

Choose a reason for hiding this comment

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

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

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");
Copy link
Contributor

Choose a reason for hiding this comment

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

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");
Copy link
Contributor

Choose a reason for hiding this comment

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

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");
Copy link
Contributor

Choose a reason for hiding this comment

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

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 {
Copy link
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 a struct for this?

Comment on lines +426 to +429
let _ = writeln!(
&mut msg,
"help: package `{}` exists at `{}`",
name.name, name.name
Copy link
Contributor

Choose a reason for hiding this comment

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

The at is giving the package name

Comment on lines +454 to +457
let _ = writeln!(
&mut msg,
"help: package `{}` exists at `{}`",
name.name, name.name
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

_path: PathBuf,
}

fn inspect_recursive_packages(
Copy link
Contributor

Choose a reason for hiding this comment

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

this name doesn't say what it is doing

Comment on lines +624 to +628
msg: &mut String,
path: &Path,
gctx: &GlobalContext,
sid: SourceId,
) -> Option<RootPackageInfo> {
Copy link
Contributor

Choose a reason for hiding this comment

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

A bit unusual to have a function like this also modify msg

}

fn inspect_recursive_packages(
msg: &mut String,
Copy link
Contributor

Choose a reason for hiding this comment

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

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 `{}`",
Copy link
Contributor

Choose a reason for hiding this comment

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

We sure are repeating this a lot

let manifest = pkg.manifest_path();
let pkg_dir = manifest
.parent()
.expect("failed to take the parent path")
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto about expect

Comment on lines +717 to +719
// } else {
// let list = rps.list_files(&pkg).unwrap();
// println!("{:?}", list);
Copy link
Contributor

Choose a reason for hiding this comment

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

dead code

Comment on lines +711 to +714
let package_info = RecursivePackageInfo {
name: pkg.name().to_string(),
_path: pkg_dir,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Why a struct?

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

Labels

A-cli-help Area: built-in command-line help A-completions Area: shell completions A-dependency-resolution Area: dependency resolution and the resolver A-documenting-cargo-itself Area: Cargo's documentation A-timings Area: timings Command-test S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants