ok/jj
1
0
Fork 0
forked from mirrors/jj

revset: don't stringify StringPatternParseError

This helps to add hint at the CLI layer.
This commit is contained in:
Yuya Nishihara 2024-03-29 13:07:31 +09:00
parent c4d48c5139
commit d759ba11f1
2 changed files with 10 additions and 6 deletions

View file

@ -167,13 +167,15 @@ fn test_bad_function_call() {
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "branches(bad:pattern)"]);
insta::assert_snapshot!(stderr, @r###"
Error: Failed to parse revset: Function "branches": Invalid string pattern kind "bad:", try prefixing with one of `exact:`, `glob:` or `substring:`
Caused by: --> 1:10
Error: Failed to parse revset: Function "branches": Invalid string pattern
Caused by:
1: --> 1:10
|
1 | branches(bad:pattern)
| ^---------^
|
= Function "branches": Invalid string pattern kind "bad:", try prefixing with one of `exact:`, `glob:` or `substring:`
= Function "branches": Invalid string pattern
2: 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()"]);

View file

@ -1449,8 +1449,10 @@ fn parse_function_argument_to_string_pattern(
}
RevsetExpression::StringPattern { kind, value } => {
// TODO: error span can be narrowed to the lhs node
StringPattern::from_str_kind(value, kind)
.map_err(|err| RevsetParseError::invalid_arguments(name, err.to_string(), span))?
StringPattern::from_str_kind(value, kind).map_err(|err| {
RevsetParseError::invalid_arguments(name, "Invalid string pattern", span)
.with_source(err)
})?
}
_ => {
return Err(RevsetParseError::invalid_arguments(
@ -2926,7 +2928,7 @@ mod tests {
parse(r#"branches(bad:"foo")"#),
Err(RevsetParseErrorKind::InvalidFunctionArguments {
name: "branches".to_owned(),
message: r#"Invalid string pattern kind "bad:", try prefixing with one of `exact:`, `glob:` or `substring:`"#.to_owned()
message: "Invalid string pattern".to_owned()
})
);
assert_eq!(