Skip to content
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

fix: add error message for github PR url in dep #15003

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

joshka
Copy link

@joshka joshka commented Jan 2, 2025

Prior to this, using a github PR URL would cause cargo to attempt to
fetch from an incorrect URL several times before failing.
Providing a github pull request url now fails with an error message
that shows how to fix the problem.

E.g.:

bar = { git = "https://github.com/foo/bar/pull/123" }

Now gives the following error message:

dependency (bar) specifies a GitHub pull request link. If you were trying to specify a specific github PR, replace the URL with the git URL (e.g. `git = "https://github.com/foo/bar.git"`) and add `rev = "refs/pull/123/head"` in the dependency declaration.

Fixes: #15001

Prior to this, using a github PR URL would cause cargo to attempt to
fetch from an incorrect URL several times before failing.
Providing a github pull request url now fails with an error message
that shows how to fix the problem.

E.g.:
```toml
bar = { git = "https://github.com/foo/bar/pull/123" }
```
Now gives the following error message:
```
dependency (bar) specifies a GitHub pull request link. If you were trying to specify a specific github PR, replace the URL with the git URL (e.g. `git = "https://github.com/foo/bar.git"`) and add `rev = "refs/pull/123/head"` in the dependency declaration.
```

Fixes: rust-lang#15001
@rustbot
Copy link
Collaborator

rustbot commented Jan 2, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @weihanglo (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 2, 2025
@@ -2151,6 +2151,37 @@ Caused by:
.run();
}

#[cargo_test]
fn github_pull_request_url() {
Copy link
Contributor

Choose a reason for hiding this comment

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

As noted in #14941, this should cover patches as well and we should have a test for it.

Copy link
Member

Choose a reason for hiding this comment

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

#15001 you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes :)

Copy link
Author

Choose a reason for hiding this comment

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

Done in d743987

@@ -2144,6 +2144,8 @@ fn to_dependency_source_id<P: ResolveToPath + Clone>(
.unwrap_or(GitReference::DefaultBranch);
let loc = git.into_url()?;

bail_if_github_pull_request(&name_in_toml, &loc)?;
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 a bit uncomfortable proactively erroring if the URL pattern matches to github, rather than providing context if what the user specified fails. I guess the worst that can happen is github allows you to clone PR URLs and we people report it and we have to remove it to allow its use. Not the worst outcome for something that is unclear if it would ever happen.

Copy link
Author

@joshka joshka Jan 3, 2025

Choose a reason for hiding this comment

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

The behavior here is the same as for how fragments are handled directly below this (though they are handled as a warning. The difference is that this causes an error later in the processing while the fragment does not. I think it's reasonable to avoid attempting to do cause an error by downloading. If this was wrong, then removing this code or changing it to a warning would be fairly low cost. How about we keep this as-is (in this PR)

[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`

Caused by:
dependency (bar) specifies a GitHub pull request link. If you were trying to specify a specific github PR, replace the URL with the git URL (e.g. `git = "https://github.com/foo/bar.git"`) and add `rev = "refs/pull/123/head"` in the dependency declaration.
Copy link
Contributor

Choose a reason for hiding this comment

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

As an error message, it should first saw what the problem is. I also feel like this requires people to parse a lot of the message to understand the fix and apply it (e.g. rather than copy/pasting)

What do you think of

  `dependencies.{name}.git = "{url}"` is not a repository.
  hint: The repository path looks like a pull request, try replacing the repository path with:
    `git = "{url}", rev = "{rev}"`

Copy link
Author

Choose a reason for hiding this comment

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

The first part is for consistency with the other error messages. How about:

dependency (bar) git url https://github.com/foo/bar/pull/123 is not a repository.
The path looks like a pull request.
Try replacing the dependency with: `git = "https://github.com/foo/bar.git" rev = "refs/pull/123/head"` in the dependency declaration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-manifest Area: Cargo.toml issues 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.

Allow specifying pull request deps using the github PR link
4 participants