Skip to content

Commit 85c9387

Browse files
committed
Replace error with warning
1 parent d743987 commit 85c9387

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::ffi::OsStr;
44
use std::path::{Path, PathBuf};
55
use std::rc::Rc;
66
use std::str::{self, FromStr};
7-
use tracing_subscriber::fmt::format;
87

98
use crate::core::summary::MissingDependencyError;
109
use crate::AlreadyPrintedError;
@@ -2145,7 +2144,7 @@ fn to_dependency_source_id<P: ResolveToPath + Clone>(
21452144
.unwrap_or(GitReference::DefaultBranch);
21462145
let loc = git.into_url()?;
21472146

2148-
bail_if_github_pull_request(&name_in_toml, &loc)?;
2147+
warn_if_github_pull_request(&name_in_toml, &loc, manifest_ctx.warnings);
21492148

21502149
if let Some(fragment) = loc.fragment() {
21512150
let msg = format!(
@@ -2187,23 +2186,26 @@ fn to_dependency_source_id<P: ResolveToPath + Clone>(
21872186

21882187
/// Checks if the URL is a GitHub pull request URL.
21892188
///
2190-
/// If the URL is a GitHub pull request URL, an error is returned with a message that explains
2191-
/// how to specify a specific git revision.
2192-
fn bail_if_github_pull_request(name_in_toml: &str, url: &Url) -> CargoResult<()> {
2189+
/// If the URL is a GitHub pull request URL, an warning is emitted with a message that explains how
2190+
/// to specify a specific git revision.
2191+
///
2192+
/// At some point in the future it might be worth considering making this a hard error, but for now
2193+
/// it's just a warning. See <https://github.com/rust-lang/cargo/pull/15003#discussion_r1908005924>.
2194+
fn warn_if_github_pull_request(name_in_toml: &str, url: &Url, warnings: &mut Vec<String>) {
21932195
if url.host_str() != Some("github.com") {
2194-
return Ok(());
2196+
return;
21952197
}
21962198
let path_components = url.path().split('/').collect::<Vec<_>>();
21972199
if let ["", owner, repo, "pull", pr_number, ..] = path_components[..] {
21982200
let repo_url = format!("https://github.com/{owner}/{repo}.git");
21992201
let rev = format!("refs/pull/{pr_number}/head");
2200-
bail!(
2202+
let warning = format!(
22012203
"dependency ({name_in_toml}) git url {url} is not a repository. \
22022204
The path looks like a pull request. Try replacing the dependency with: \
22032205
`git = \"{repo_url}\" rev = \"{rev}\"` in the dependency declaration.",
22042206
);
2207+
warnings.push(warning);
22052208
}
2206-
Ok(())
22072209
}
22082210

22092211
pub(crate) fn lookup_path_base<'a>(

tests/testsuite/bad_config.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,10 +2173,29 @@ fn github_pull_request_url() {
21732173
p.cargo("check -v")
21742174
.with_status(101)
21752175
.with_stderr_data(str![[r#"
2176-
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
2176+
[WARNING] 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.
2177+
[UPDATING] git repository `https://github.com/foo/bar/pull/123`
2178+
[WARNING] spurious network error (3 tries remaining): unexpected http status code: 404; class=Http (34)
2179+
[WARNING] spurious network error (2 tries remaining): unexpected http status code: 404; class=Http (34)
2180+
[WARNING] spurious network error (1 tries remaining): unexpected http status code: 404; class=Http (34)
2181+
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.0 ([ROOT]/foo)`
2182+
2183+
Caused by:
2184+
failed to load source for dependency `bar`
2185+
2186+
Caused by:
2187+
Unable to update https://github.com/foo/bar/pull/123
2188+
2189+
Caused by:
2190+
failed to clone into: [ROOT]/home/.cargo/git/db/123-[HASH]
2191+
2192+
Caused by:
2193+
network failure seems to have happened
2194+
if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
2195+
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
21772196
21782197
Caused by:
2179-
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.
2198+
unexpected http status code: 404; class=Http (34)
21802199
21812200
"#]])
21822201
.run();

tests/testsuite/patch.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,6 @@ fn patch_to_git() {
359359

360360
#[cargo_test]
361361
fn patch_to_git_pull_request() {
362-
let bar = git::repo(&paths::root().join("override"))
363-
.file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
364-
.file("src/lib.rs", "pub fn bar() {}")
365-
.build();
366-
367362
Package::new("bar", "0.1.0").publish();
368363

369364
let p = project()
@@ -392,10 +387,26 @@ fn patch_to_git_pull_request() {
392387
p.cargo("check -v")
393388
.with_status(101)
394389
.with_stderr_data(str![[r#"
395-
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
390+
[WARNING] 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.
391+
[UPDATING] git repository `https://github.com/foo/bar/pull/123`
392+
[WARNING] spurious network error (3 tries remaining): unexpected http status code: 404; class=Http (34)
393+
[WARNING] spurious network error (2 tries remaining): unexpected http status code: 404; class=Http (34)
394+
[WARNING] spurious network error (1 tries remaining): unexpected http status code: 404; class=Http (34)
395+
[ERROR] failed to load source for dependency `bar`
396+
397+
Caused by:
398+
Unable to update https://github.com/foo/bar/pull/123
399+
400+
Caused by:
401+
failed to clone into: [ROOT]/home/.cargo/git/db/123-[HASH]
402+
403+
Caused by:
404+
network failure seems to have happened
405+
if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
406+
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
396407
397408
Caused by:
398-
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.
409+
unexpected http status code: 404; class=Http (34)
399410
400411
"#]])
401412
.run();

0 commit comments

Comments
 (0)