-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error messages for wrong target paths #9116
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this perhaps use tthe
inferred
list at the top to generate a precise list of candidates attempted? Otherwise this misses out that eitherbenches/foo.rs
orbenches/foo/main.rs
could exist. (e.g.benches/foo
could exist when this says it doesn't b/c you happened to be missingbenches/foo/main.rs
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @alexcrichton Thanks for the catch!! I didn't thought about that!
There's only one problem. This slice is constructed here
And as you see,
infer_from_directory
you send thebenches
dir to the fn. And obviously, that resolves into an empty array because the bench is located underbench/
and notbenches
.I don't really see how to tackle that. Since we need to "guess" which is the wrong path. And if we parse from
package_root
looking for similar names to benches, we might end up in undesired places.Which is your suggestion?
If you want to clarify even more, We can go for a suggestion message below the err saying something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that's a good point. I think there will need to be some refactoring for this in any case though. The error message is already slightly incorrect in that if we found two candidates it says that something wasn't found when actually we found two things. Similarly I'm worried about the catch-all
_ => target_kind
here since that may produce incorrect messages trying to look in a folder likelib/foo
for example.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't IIUC. The catch all is precisely what handles
lib
to be matched tolib
itself. The others are the ones which can contain wrong folder names. But maybe I'm missing something.We could parse the top level of the workspace looking for
example
,test
,bins
orbench
folders. If that's the case, we try to extractinferred
from there and we will be able to formulate a better error message. Otherways. I really don;t know what we can do. Since literally the path could be whatever.Do you have any similar situations in other places of the crate? Do you have any suggestions on what to go for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a set of paths that Cargo probes for for targets which don't list a
path
. That set I think should be refactored to be able to be passed in here explicitly so this doesn't have to reconstruct or re-infer what the missing paths were. I think that refactoring would solve all of my concerns here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation Alex. Could you point where
Cargo probes for for targets which don't list a path
? I've been looking across the repo for something similar to aLayout
structure where these targets without listed path are treated or stored and haven't seen it.I checked from the creation of the
Workspace
till the execution of the benches and nothing seemed to me like was cheking this "missed" targets.That would be really helpful for me so I can make another PR to refactor this and then, use that so that the error message gets improved.
I can also include the refactor here, whatever you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
probe
logic is in the functions in this module (inferred_bins
,inferred_lib
,infer_from_directory
). I think the refactoring would be to change those to return a list of potential candidates (essentially, remove the checks forpath.exists()
), and then the code that creates the targets (toml_targets_and_inferred
I think) will need to check for the first path in that candidate list that exists (something likeinferred.iter().find(|p| p.exists())
). Then, you can pass that list of candidates totarget_path
so that it can include them in the error message.It may need to be careful since those paths are absolute. I'm not sure how that should be displayed, but maybe strip the current directory from the prefix?