From 93c707a469ee5f714be72c1935f1443567db9dc7 Mon Sep 17 00:00:00 2001 From: "Alexis (Poliorcetics) Bourget" <ab_jujutsu@poliorcetiq.eu> Date: Fri, 15 Mar 2024 23:50:21 +0100 Subject: [PATCH] lib: improve error message for invalid string pattern, suggesting to use one of the known one --- cli/tests/test_branch_command.rs | 2 +- cli/tests/test_revset_output.rs | 2 +- lib/src/revset.rs | 2 +- lib/src/str_util.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/tests/test_branch_command.rs b/cli/tests/test_branch_command.rs index a37ef165b..4fcd6eaf0 100644 --- a/cli/tests/test_branch_command.rs +++ b/cli/tests/test_branch_command.rs @@ -396,7 +396,7 @@ fn test_branch_delete_glob() { // Unknown pattern kind let stderr = test_env.jj_cmd_cli_error(&repo_path, &["branch", "forget", "whatever:branch"]); insta::assert_snapshot!(stderr, @r###" - error: invalid value 'whatever:branch' for '[NAMES]...': Invalid string pattern kind "whatever" + error: invalid value 'whatever:branch' for '[NAMES]...': Invalid string pattern kind "whatever:", try prefixing with one of `exact:`, `glob:` or `substring:` For more information, try '--help'. "###); diff --git a/cli/tests/test_revset_output.rs b/cli/tests/test_revset_output.rs index de836cc3d..8038e4a47 100644 --- a/cli/tests/test_revset_output.rs +++ b/cli/tests/test_revset_output.rs @@ -157,7 +157,7 @@ fn test_bad_function_call() { 1 | branches(bad:pattern) | ^---------^ | - = Invalid arguments to revset function "branches": Invalid string pattern kind "bad" + = Invalid arguments to revset function "branches": Invalid string pattern kind "bad:", try prefixing with one of `exact:`, `glob:` or `substring:` "###); let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "root()::whatever()"]); diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 8a675093f..6dd7f07b5 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -2932,7 +2932,7 @@ mod tests { parse(r#"branches(bad:"foo")"#), Err(RevsetParseErrorKind::InvalidFunctionArguments { name: "branches".to_owned(), - message: r#"Invalid string pattern kind "bad""#.to_owned() + message: r#"Invalid string pattern kind "bad:", try prefixing with one of `exact:`, `glob:` or `substring:`"#.to_owned() }) ); assert_eq!( diff --git a/lib/src/str_util.rs b/lib/src/str_util.rs index 36df7ac5b..ffe58e0a4 100644 --- a/lib/src/str_util.rs +++ b/lib/src/str_util.rs @@ -25,7 +25,7 @@ use thiserror::Error; #[derive(Debug, Error)] pub enum StringPatternParseError { /// Unknown pattern kind is specified. - #[error(r#"Invalid string pattern kind "{0}""#)] + #[error(r#"Invalid string pattern kind "{0}:", try prefixing with one of `exact:`, `glob:` or `substring:`"#)] InvalidKind(String), /// Failed to parse glob pattern. #[error(transparent)]