Skip to content

Commit 5fe481d

Browse files
authored
fix(lock): Be moore direct in the error message (#16233)
### What does this PR try to resolve? This puts the action that failed front and center, rather than burying it burying it after some long, variable-length content. ### How to test and review this PR?
2 parents 8c4a25c + 1302fd3 commit 5fe481d

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/cargo/ops/lockfile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes
5555
if let Some(locked_flag) = ws.gctx().locked_flag() {
5656
let lockfile_path = lock_root.as_path_unlocked().join(LOCKFILE_NAME);
5757
let action = if lockfile_path.exists() {
58-
"updated"
58+
"update"
5959
} else {
60-
"created"
60+
"create"
6161
};
6262
let lockfile_path = lockfile_path.display();
6363
anyhow::bail!(
64-
"the lock file {lockfile_path} needs to be {action} but {locked_flag} was passed to prevent this\n\
64+
"cannot {action} the lock file {lockfile_path} because {locked_flag} was passed to prevent this\n\
6565
help: to generate the lock file without accessing the network, \
6666
remove the {locked_flag} flag and use --offline instead."
6767
);

tests/testsuite/lockfile_compat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ fn locked_correct_error() {
517517
.with_status(101)
518518
.with_stderr_data(str![[r#"
519519
[UPDATING] `dummy-registry` index
520-
[ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be created but --locked was passed to prevent this
520+
[ERROR] cannot create the lock file [ROOT]/foo/Cargo.lock because --locked was passed to prevent this
521521
[HELP] to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.
522522
523523
"#]])

tests/testsuite/offline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ fn offline_and_frozen_and_no_lock() {
767767
p.cargo("check --frozen --offline")
768768
.with_status(101)
769769
.with_stderr_data(str![[r#"
770-
[ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be created but --frozen was passed to prevent this
770+
[ERROR] cannot create the lock file [ROOT]/foo/Cargo.lock because --frozen was passed to prevent this
771771
[HELP] to generate the lock file without accessing the network, remove the --frozen flag and use --offline instead.
772772
773773
"#]])
@@ -780,7 +780,7 @@ fn offline_and_locked_and_no_frozen() {
780780
p.cargo("check --locked --offline")
781781
.with_status(101)
782782
.with_stderr_data(str![[r#"
783-
[ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be created but --locked was passed to prevent this
783+
[ERROR] cannot create the lock file [ROOT]/foo/Cargo.lock because --locked was passed to prevent this
784784
[HELP] to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.
785785
786786
"#]])

0 commit comments

Comments
 (0)