Skip to content

Commit

Permalink
Auto merge of #7655 - ehuss:offline-patched-error, r=alexcrichton
Browse files Browse the repository at this point in the history
Remove --offline empty index error.

This reverts the error added in #6871 which attempts to provide a "nicer" error message if `--offline` is used with an empty index. I was concerned about false positives, and sure enough someone found one. If all deps are patched, it is OK for the index to be empty, because the resolver will just use the patched entries.

I considered trying to move the error to another location, but I think it would require significant changes to the registry API (which is already hard to follow). I figure the "not found" error message is good enough with the "don't use --offline" hint.

Closes #7582
  • Loading branch information
bors committed Dec 4, 2019
2 parents 2e4195f + 1437976 commit 76cdf93
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
12 changes: 0 additions & 12 deletions src/cargo/sources/registry/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,6 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {

fn update_index(&mut self) -> CargoResult<()> {
if self.config.offline() {
if self.repo()?.is_empty()? {
// An empty repository is guaranteed to fail, since hitting
// this path means we need at least one crate. This is an
// attempt to provide a better error message other than "no
// matching package named …".
failure::bail!(
"unable to fetch {} in offline mode\n\
Try running without the offline flag, or try running \
`cargo fetch` within your project directory before going offline.",
self.source_id
);
}
return Ok(());
}
if self.config.cli_unstable().no_index_update {
Expand Down
57 changes: 40 additions & 17 deletions tests/testsuite/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ fn cargo_compile_with_downloaded_dependency_with_offline() {

#[cargo_test]
fn cargo_compile_offline_not_try_update() {
// When --offline needs to download the registry, provide a reasonable
// error hint to run without --offline.
let p = project()
.at("bar")
.file(
Expand All @@ -160,28 +162,23 @@ fn cargo_compile_offline_not_try_update() {
.file("src/lib.rs", "")
.build();

let msg = "\
[ERROR] no matching package named `not_cached_dep` found
location searched: registry `https://github.com/rust-lang/crates.io-index`
required by package `bar v0.1.0 ([..]/bar)`
As a reminder, you're using offline mode (--offline) which can sometimes cause \
surprising resolution failures, if this error is too confusing you may wish to \
retry without the offline flag.
";

p.cargo("build --offline")
.with_status(101)
.with_stderr(
"\
[ERROR] failed to load source for a dependency on `not_cached_dep`
Caused by:
Unable to update registry `https://github.com/rust-lang/crates.io-index`
Caused by:
unable to fetch registry `https://github.com/rust-lang/crates.io-index` in offline mode
Try running without the offline flag, or try running `cargo fetch` within your \
project directory before going offline.
",
)
.with_stderr(msg)
.run();

// While we're here, also check the config works.
p.change_file(".cargo/config", "net.offline = true");
p.cargo("build")
.with_status(101)
.with_stderr_contains("[..]Unable to update registry[..]")
.run();
p.cargo("build").with_status(101).with_stderr(msg).run();
}

#[cargo_test]
Expand Down Expand Up @@ -536,3 +533,29 @@ retry without the offline flag.
")
.run();
}

#[cargo_test]
fn offline_with_all_patched() {
// Offline works if everything is patched.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
dep = "1.0"
[patch.crates-io]
dep = {path = "dep"}
"#,
)
.file("src/lib.rs", "pub fn f() { dep::foo(); }")
.file("dep/Cargo.toml", &basic_manifest("dep", "1.0.0"))
.file("dep/src/lib.rs", "pub fn foo() {}")
.build();

p.cargo("check --offline").run();
}

0 comments on commit 76cdf93

Please sign in to comment.