Skip to content

Commit

Permalink
cli: improve snapshot.max-new-file-size error message
Browse files Browse the repository at this point in the history
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 <[email protected]>
Change-Id: Ide0c86fdfb40d66f970ceaef7b60a71392d2cd4b
  • Loading branch information
thoughtpolice committed Apr 4, 2024
1 parent 882f721 commit fd3667e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
27 changes: 21 additions & 6 deletions cli/src/command_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,27 @@ impl From<OpsetEvaluationError> for CommandError {
impl From<SnapshotError> 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),
}
}
Expand Down
11 changes: 8 additions & 3 deletions cli/tests/test_working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"###);
}

0 comments on commit fd3667e

Please sign in to comment.