From 1302fd3c25ac674d79b1d0bce0daa99d25c5b316 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 10 Nov 2025 09:35:32 -0600 Subject: [PATCH] fix(lock): Be moore direct in the error message This puts the action that failed front and center, rather than burying it burying it after some long, variable-length content. --- src/cargo/ops/lockfile.rs | 6 +++--- tests/testsuite/lockfile_compat.rs | 2 +- tests/testsuite/offline.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index f0abcbe8bc8..cc165c33b1e 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -55,13 +55,13 @@ 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" + "update" } else { - "created" + "create" }; let lockfile_path = lockfile_path.display(); anyhow::bail!( - "the lock file {lockfile_path} needs to be {action} but {locked_flag} was passed to prevent this\n\ + "cannot {action} the lock file {lockfile_path} because {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 8de08cc3a82..c3748c7b7df 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 created but --locked was passed to prevent this +[ERROR] cannot create the lock file [ROOT]/foo/Cargo.lock because --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 cce0ffc9775..8b00a1a843b 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 created but --frozen was passed to prevent this +[ERROR] cannot create the lock file [ROOT]/foo/Cargo.lock because --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 created but --locked was passed to prevent this +[ERROR] cannot create the lock file [ROOT]/foo/Cargo.lock because --locked was passed to prevent this [HELP] to generate the lock file without accessing the network, remove the --locked flag and use --offline instead. "#]])