From 7f1d902f573249e5c815d302e3a8b1a5f6cd823d Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 16 Dec 2024 15:23:16 -0600 Subject: [PATCH] snapshot: demo unreadable error message on invalid ignore A user on Discord ran into this error message, and they were confused about why they were getting it. The next commit will improve the error messages. --- cli/tests/test_working_copy.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cli/tests/test_working_copy.rs b/cli/tests/test_working_copy.rs index dc2acccb20..7a8ecee2d8 100644 --- a/cli/tests/test_working_copy.rs +++ b/cli/tests/test_working_copy.rs @@ -227,3 +227,27 @@ fn test_materialize_and_snapshot_different_conflict_markers() { line 3 "##); } + +#[test] +fn test_snapshot_invalid_ignore_pattern() { + let test_env = TestEnvironment::default(); + test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); + let repo_path = test_env.env_root().join("repo"); + let gitignore_path = repo_path.join(".gitignore"); + + // Test invalid pattern in .gitignore + std::fs::write(&gitignore_path, " []\n").unwrap(); + insta::assert_snapshot!(test_env.jj_cmd_internal_error(&repo_path, &["st"]), @r#" + Internal error: Failed to snapshot the working copy + Caused by: error parsing glob ' []': unclosed character class; missing ']' + "#); + + // Test invalid UTF-8 in .gitignore + std::fs::write(&gitignore_path, b"\xff\n").unwrap(); + insta::assert_snapshot!(test_env.jj_cmd_internal_error(&repo_path, &["st"]), @r##" + Internal error: Failed to snapshot the working copy + Caused by: + 1: invalid UTF-8 for ignore pattern in on line #1: � + 2: invalid utf-8 sequence of 1 bytes from index 0 + "##); +}