lib: improve error message for invalid string pattern, suggesting to use one of the known one

This commit is contained in:
Alexis (Poliorcetics) Bourget 2024-03-15 23:50:21 +01:00 committed by Poliorcetics
parent 8600750fce
commit 93c707a469
4 changed files with 4 additions and 4 deletions

View file

@ -396,7 +396,7 @@ fn test_branch_delete_glob() {
// Unknown pattern kind // Unknown pattern kind
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["branch", "forget", "whatever:branch"]); let stderr = test_env.jj_cmd_cli_error(&repo_path, &["branch", "forget", "whatever:branch"]);
insta::assert_snapshot!(stderr, @r###" 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'. For more information, try '--help'.
"###); "###);

View file

@ -157,7 +157,7 @@ fn test_bad_function_call() {
1 | branches(bad:pattern) 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()"]); let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "root()::whatever()"]);

View file

@ -2932,7 +2932,7 @@ mod tests {
parse(r#"branches(bad:"foo")"#), parse(r#"branches(bad:"foo")"#),
Err(RevsetParseErrorKind::InvalidFunctionArguments { Err(RevsetParseErrorKind::InvalidFunctionArguments {
name: "branches".to_owned(), 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!( assert_eq!(

View file

@ -25,7 +25,7 @@ use thiserror::Error;
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum StringPatternParseError { pub enum StringPatternParseError {
/// Unknown pattern kind is specified. /// 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), InvalidKind(String),
/// Failed to parse glob pattern. /// Failed to parse glob pattern.
#[error(transparent)] #[error(transparent)]