From 048d21d6d7651c746d210ed99f1b0710e85b8705 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 7 Nov 2025 16:24:54 -0600 Subject: [PATCH 1/4] fix(lock): Formulate the --locked suggestion with more direct wording --- src/cargo/ops/lockfile.rs | 2 +- tests/testsuite/lockfile_compat.rs | 2 +- tests/testsuite/offline.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index 9066f1decb2..7d144029b9e 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -55,7 +55,7 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes if let Some(locked_flag) = ws.gctx().locked_flag() { anyhow::bail!( "the lock file {} needs to be updated but {} was passed to prevent this\n\ - If you want to try to generate the lock file without accessing the network, \ + help: to generate the lock file without accessing the network, \ remove the {} flag and use --offline instead.", lock_root.as_path_unlocked().join(LOCKFILE_NAME).display(), locked_flag, diff --git a/tests/testsuite/lockfile_compat.rs b/tests/testsuite/lockfile_compat.rs index cc8961a1e45..c32f95d886f 100644 --- a/tests/testsuite/lockfile_compat.rs +++ b/tests/testsuite/lockfile_compat.rs @@ -518,7 +518,7 @@ fn locked_correct_error() { .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be updated but --locked was passed to prevent this -If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead. +[HELP] to generate the lock file without accessing the network, remove the --locked flag and use --offline instead. "#]]) .run(); diff --git a/tests/testsuite/offline.rs b/tests/testsuite/offline.rs index 8a56c8cc363..eb6f83a4b9f 100644 --- a/tests/testsuite/offline.rs +++ b/tests/testsuite/offline.rs @@ -768,7 +768,7 @@ fn offline_and_frozen_and_no_lock() { .with_status(101) .with_stderr_data(str![[r#" [ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be updated but --frozen was passed to prevent this -If you want to try to generate the lock file without accessing the network, remove the --frozen flag and use --offline instead. +[HELP] to generate the lock file without accessing the network, remove the --frozen flag and use --offline instead. "#]]) .run(); @@ -781,7 +781,7 @@ fn offline_and_locked_and_no_frozen() { .with_status(101) .with_stderr_data(str![[r#" [ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be updated but --locked was passed to prevent this -If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead. +[HELP] to generate the lock file without accessing the network, remove the --locked flag and use --offline instead. "#]]) .run(); From f5b0fffbee8a84891e347a005dca4be5ad28d942 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 7 Nov 2025 16:26:49 -0600 Subject: [PATCH 2/4] refactor(lock): Pull out path for reuse --- src/cargo/ops/lockfile.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index 7d144029b9e..489a7f97dfb 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -53,11 +53,12 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes } if let Some(locked_flag) = ws.gctx().locked_flag() { + let lockfile_path = lock_root.as_path_unlocked().join(LOCKFILE_NAME); anyhow::bail!( "the lock file {} needs to be updated but {} was passed to prevent this\n\ help: to generate the lock file without accessing the network, \ remove the {} flag and use --offline instead.", - lock_root.as_path_unlocked().join(LOCKFILE_NAME).display(), + lockfile_path.display(), locked_flag, locked_flag ); From 6c46d6b2d67180713cd75b9fb24344c590270bda Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 7 Nov 2025 16:27:43 -0600 Subject: [PATCH 3/4] refactor(lock): Switch to string interpolation --- src/cargo/ops/lockfile.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index 489a7f97dfb..a0dad43e313 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -54,13 +54,11 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes if let Some(locked_flag) = ws.gctx().locked_flag() { let lockfile_path = lock_root.as_path_unlocked().join(LOCKFILE_NAME); + let lockfile_path = lockfile_path.display(); anyhow::bail!( - "the lock file {} needs to be updated but {} was passed to prevent this\n\ + "the lock file {lockfile_path} needs to be updated but {locked_flag} was passed to prevent this\n\ help: to generate the lock file without accessing the network, \ - remove the {} flag and use --offline instead.", - lockfile_path.display(), - locked_flag, - locked_flag + remove the {locked_flag} flag and use --offline instead." ); } From 2ba6f8cbe47225141533eb4183b5ea2ca0432bca Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 7 Nov 2025 16:29:58 -0600 Subject: [PATCH 4/4] fix(lock): In error, differentiate between creating and updating lockfile Fixes #10503 --- src/cargo/ops/lockfile.rs | 7 ++++++- tests/testsuite/lockfile_compat.rs | 2 +- tests/testsuite/offline.rs | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index a0dad43e313..f0abcbe8bc8 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -54,9 +54,14 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes if let Some(locked_flag) = ws.gctx().locked_flag() { let lockfile_path = lock_root.as_path_unlocked().join(LOCKFILE_NAME); + let action = if lockfile_path.exists() { + "updated" + } else { + "created" + }; let lockfile_path = lockfile_path.display(); anyhow::bail!( - "the lock file {lockfile_path} needs to be updated but {locked_flag} was passed to prevent this\n\ + "the lock file {lockfile_path} needs to be {action} but {locked_flag} was passed to prevent this\n\ help: to generate the lock file without accessing the network, \ remove the {locked_flag} flag and use --offline instead." ); diff --git a/tests/testsuite/lockfile_compat.rs b/tests/testsuite/lockfile_compat.rs index c32f95d886f..8de08cc3a82 100644 --- a/tests/testsuite/lockfile_compat.rs +++ b/tests/testsuite/lockfile_compat.rs @@ -517,7 +517,7 @@ fn locked_correct_error() { .with_status(101) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index -[ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be updated but --locked was passed to prevent this +[ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be created but --locked was passed to prevent this [HELP] to generate the lock file without accessing the network, remove the --locked flag and use --offline instead. "#]]) diff --git a/tests/testsuite/offline.rs b/tests/testsuite/offline.rs index eb6f83a4b9f..cce0ffc9775 100644 --- a/tests/testsuite/offline.rs +++ b/tests/testsuite/offline.rs @@ -767,7 +767,7 @@ fn offline_and_frozen_and_no_lock() { p.cargo("check --frozen --offline") .with_status(101) .with_stderr_data(str![[r#" -[ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be updated but --frozen was passed to prevent this +[ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be created but --frozen was passed to prevent this [HELP] to generate the lock file without accessing the network, remove the --frozen flag and use --offline instead. "#]]) @@ -780,7 +780,7 @@ fn offline_and_locked_and_no_frozen() { p.cargo("check --locked --offline") .with_status(101) .with_stderr_data(str![[r#" -[ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be updated but --locked was passed to prevent this +[ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be created but --locked was passed to prevent this [HELP] to generate the lock file without accessing the network, remove the --locked flag and use --offline instead. "#]])