Skip to content

Commit b0e2cc5

Browse files
committed
Auto merge of #9644 - ehuss:offline-and-frozen, r=alexcrichton
Adjust error message with offline and frozen. Using --offline with --frozen when the lock file needed to be updated gave a confusing error message. This updates it to make it slightly clearer. Closes #9572
2 parents 4952979 + dd8fa91 commit b0e2cc5

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/cargo/ops/lockfile.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes
4646
}
4747

4848
if !ws.config().lock_update_allowed() {
49-
if ws.config().offline() {
50-
anyhow::bail!("can't update in the offline mode");
51-
}
52-
5349
let flag = if ws.config().network_allowed() {
5450
"--locked"
5551
} else {
@@ -58,8 +54,9 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes
5854
anyhow::bail!(
5955
"the lock file {} needs to be updated but {} was passed to prevent this\n\
6056
If you want to try to generate the lock file without accessing the network, \
61-
use the --offline flag.",
57+
remove the {} flag and use --offline instead.",
6258
ws.root().to_path_buf().join("Cargo.lock").display(),
59+
flag,
6360
flag
6461
);
6562
}

tests/testsuite/lockfile_compat.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ fn locked_correct_error() {
511511
"\
512512
[UPDATING] `[..]` index
513513
error: the lock file [CWD]/Cargo.lock needs to be updated but --locked was passed to prevent this
514-
If you want to try to generate the lock file without accessing the network, use the --offline flag.
514+
If you want to try to generate the lock file without accessing the network, \
515+
remove the --locked flag and use --offline instead.
515516
",
516517
)
517518
.run();

tests/testsuite/offline.rs

+13
Original file line numberDiff line numberDiff line change
@@ -685,3 +685,16 @@ retry without the offline flag.
685685
)
686686
.run();
687687
}
688+
689+
#[cargo_test]
690+
fn offline_and_frozen_and_no_lock() {
691+
let p = project().file("src/lib.rs", "").build();
692+
p.cargo("build --frozen --offline")
693+
.with_status(101)
694+
.with_stderr("\
695+
error: the lock file [ROOT]/foo/Cargo.lock needs to be updated but --frozen was passed to prevent this
696+
If you want to try to generate the lock file without accessing the network, \
697+
remove the --frozen flag and use --offline instead.
698+
")
699+
.run();
700+
}

0 commit comments

Comments
 (0)