Skip to content

Remove --offline empty index error. #7655

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

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}