From 5c37862380e3fc729a65fe2a5b110c4ff6a97f22 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Thu, 28 Mar 2024 15:45:31 -0500 Subject: [PATCH] cli: improve `snapshot.max-new-file-size` error message For new users this results in a significantly better error output, that actually shows them how to solve the problem, and why it happened. Signed-off-by: Austin Seipp Change-Id: Ide0c86fdfb40d66f970ceaef7b60a71392d2cd4b --- cli/src/command_error.rs | 27 +++++++++++++++++++++------ cli/tests/test_working_copy.rs | 11 ++++++++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/cli/src/command_error.rs b/cli/src/command_error.rs index 4aa87af6a1..0c7a493588 100644 --- a/cli/src/command_error.rs +++ b/cli/src/command_error.rs @@ -295,12 +295,27 @@ impl From for CommandError { impl From for CommandError { fn from(err: SnapshotError) -> Self { match err { - SnapshotError::NewFileTooLarge { .. } => { - user_error_with_message("Failed to snapshot the working copy", err).hinted( - r#"Increase the value of the `snapshot.max-new-file-size` config option if you -want this file to be snapshotted. Otherwise add it to your `.gitignore` file."#, - ) - } + SnapshotError::NewFileTooLarge { + path, + size, + max_size, + } => user_error(format!( + "Failed to snapshot the working copy\nThe file '{}' is too large to be \ + snapshotted ({} bytes).\nThe maximum size allowed is {} bytes.", + path.display(), + size.0, + max_size.0 + )) + .hinted(format!( + "This is to prevent large files from being added on accident. You can fix this \ + error by: + - Adding the file to `.gitignore` + - Run `jj config set --repo snapshot.max-new-file-size \"{}B\"` + This will increase the maximum file size allowed for new files, in this repository only. + - Run `jj --config-toml 'snapshot.max-new-file-size=\"{}B\"' st` + This will increase the maximum file size allowed for new files, for this command only.", + size.0, size.0 + )), err => internal_error_with_message("Failed to snapshot the working copy", err), } } diff --git a/cli/tests/test_working_copy.rs b/cli/tests/test_working_copy.rs index 461125b7f6..a7bacea343 100644 --- a/cli/tests/test_working_copy.rs +++ b/cli/tests/test_working_copy.rs @@ -25,8 +25,13 @@ fn test_snapshot_large_file() { let stderr = test_env.jj_cmd_failure(&repo_path, &["files"]); insta::assert_snapshot!(stderr, @r###" Error: Failed to snapshot the working copy - Caused by: New file $TEST_ENV/repo/large of size ~13.0B exceeds snapshot.max-new-file-size (10.0B) - Hint: Increase the value of the `snapshot.max-new-file-size` config option if you - want this file to be snapshotted. Otherwise add it to your `.gitignore` file. + The file '$TEST_ENV/repo/large' is too large to be snapshotted (13 bytes). + The maximum size allowed is 10 bytes. + Hint: This is to prevent large files from being added on accident. You can fix this error by: + - Adding the file to `.gitignore` + - Run `jj config set --repo snapshot.max-new-file-size "13B"` + This will increase the maximum file size allowed for new files, in this repository only. + - Run `jj --config-toml 'snapshot.max-new-file-size="13B"' st` + This will increase the maximum file size allowed for new files, for this command only. "###); }