Skip to content

Commit 22c647c

Browse files
joshkamotorailgun
authored andcommitted
Replace error with warning
1 parent 00b5056 commit 22c647c

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
@@ -5,7 +5,6 @@ use std::ffi::OsStr;
55
use std::path::{Path, PathBuf};
66
use std::rc::Rc;
77
use std::str::{self, FromStr};
8-
use tracing_subscriber::fmt::format;
98

109
use crate::AlreadyPrintedError;
1110
use crate::core::summary::MissingDependencyError;
@@ -2390,7 +2389,7 @@ fn to_dependency_source_id<P: ResolveToPath + Clone>(
23902389
.unwrap_or(GitReference::DefaultBranch);
23912390
let loc = git.into_url()?;
23922391

2393-
bail_if_github_pull_request(&name_in_toml, &loc)?;
2392+
warn_if_github_pull_request(&name_in_toml, &loc, manifest_ctx.warnings);
23942393

23952394
if let Some(fragment) = loc.fragment() {
23962395
let msg = format!(
@@ -2432,23 +2431,26 @@ fn to_dependency_source_id<P: ResolveToPath + Clone>(
24322431

24332432
/// Checks if the URL is a GitHub pull request URL.
24342433
///
2435-
/// If the URL is a GitHub pull request URL, an error is returned with a message that explains
2436-
/// how to specify a specific git revision.
2437-
fn bail_if_github_pull_request(name_in_toml: &str, url: &Url) -> CargoResult<()> {
2434+
/// If the URL is a GitHub pull request URL, an warning is emitted with a message that explains how
2435+
/// to specify a specific git revision.
2436+
///
2437+
/// At some point in the future it might be worth considering making this a hard error, but for now
2438+
/// it's just a warning. See <https://github.com/rust-lang/cargo/pull/15003#discussion_r1908005924>.
2439+
fn warn_if_github_pull_request(name_in_toml: &str, url: &Url, warnings: &mut Vec<String>) {
24382440
if url.host_str() != Some("github.com") {
2439-
return Ok(());
2441+
return;
24402442
}
24412443
let path_components = url.path().split('/').collect::<Vec<_>>();
24422444
if let ["", owner, repo, "pull", pr_number, ..] = path_components[..] {
24432445
let repo_url = format!("https://github.com/{owner}/{repo}.git");
24442446
let rev = format!("refs/pull/{pr_number}/head");
2445-
bail!(
2447+
let warning = format!(
24462448
"dependency ({name_in_toml}) git url {url} is not a repository. \
24472449
The path looks like a pull request. Try replacing the dependency with: \
24482450
`git = \"{repo_url}\" rev = \"{rev}\"` in the dependency declaration.",
24492451
);
2452+
warnings.push(warning);
24502453
}
2451-
Ok(())
24522454
}
24532455

24542456
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
@@ -2281,10 +2281,29 @@ fn github_pull_request_url() {
22812281
p.cargo("check -v")
22822282
.with_status(101)
22832283
.with_stderr_data(str![[r#"
2284-
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
2284+
[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.
2285+
[UPDATING] git repository `https://github.com/foo/bar/pull/123`
2286+
[WARNING] spurious network error (3 tries remaining): unexpected http status code: 404; class=Http (34)
2287+
[WARNING] spurious network error (2 tries remaining): unexpected http status code: 404; class=Http (34)
2288+
[WARNING] spurious network error (1 tries remaining): unexpected http status code: 404; class=Http (34)
2289+
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.0 ([ROOT]/foo)`
2290+
2291+
Caused by:
2292+
failed to load source for dependency `bar`
2293+
2294+
Caused by:
2295+
Unable to update https://github.com/foo/bar/pull/123
2296+
2297+
Caused by:
2298+
failed to clone into: [ROOT]/home/.cargo/git/db/123-[HASH]
2299+
2300+
Caused by:
2301+
network failure seems to have happened
2302+
if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
2303+
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
22852304
22862305
Caused by:
2287-
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.
2306+
unexpected http status code: 404; class=Http (34)
22882307
22892308
"#]])
22902309
.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)