Skip to content

Commit

Permalink
cli: show hint for inner fileset/revset/template errors
Browse files Browse the repository at this point in the history
Note that find_source_parse_error_hint() has recursion, but it should terminate
because err.source() shouldn't have a cycle.
  • Loading branch information
yuja committed May 4, 2024
1 parent b7cfd95 commit eac7f99
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
10 changes: 10 additions & 0 deletions cli/src/command_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,18 @@ fn find_source_parse_error_hint(err: &dyn error::Error) -> Option<String> {
let source = err.source()?;
if let Some(source) = source.downcast_ref() {
file_pattern_parse_error_hint(source)
} else if let Some(source) = source.downcast_ref() {
fileset_parse_error_hint(source)
} else if let Some(source) = source.downcast_ref() {
revset_parse_error_hint(source)
} else if let Some(source) = source.downcast_ref() {
revset_resolution_error_hint(source)
} else if let Some(UserRevsetEvaluationError::Resolution(source)) = source.downcast_ref() {
revset_resolution_error_hint(source)
} else if let Some(source) = source.downcast_ref() {
string_pattern_parse_error_hint(source)
} else if let Some(source) = source.downcast_ref() {
template_parse_error_hint(source)
} else {
None
}
Expand Down
32 changes: 28 additions & 4 deletions cli/tests/test_commit_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,17 +742,41 @@ fn test_log_contained_in() {

let stderr = test_env.jj_cmd_failure(
&repo_path,
&["log", "-r::", "-T", &template_for_revset("unknown_symbol")],
&["log", "-r::", "-T", &template_for_revset("author(x:'y')")],
);
insta::assert_snapshot!(stderr, @r###"
Error: Failed to parse template: Failed to parse revset
Caused by:
1: --> 5:28
|
5 | if(self.contained_in("author(x:'y')"), "[contained_in]"),
| ^-------------^
|
= Failed to parse revset
2: --> 1:8
|
1 | author(x:'y')
| ^---^
|
= Function "author": Invalid string pattern
3: Invalid string pattern kind "x:"
Hint: Try prefixing with one of `exact:`, `glob:` or `substring:`
"###);

let stderr = test_env.jj_cmd_failure(
&repo_path,
&["log", "-r::", "-T", &template_for_revset("maine")],
);
insta::assert_snapshot!(stderr, @r###"
Error: Failed to parse template: Failed to evaluate revset
Caused by:
1: --> 5:28
|
5 | if(self.contained_in("unknown_symbol"), "[contained_in]"),
| ^--------------^
5 | if(self.contained_in("maine"), "[contained_in]"),
| ^-----^
|
= Failed to evaluate revset
2: Revision "unknown_symbol" doesn't exist
2: Revision "maine" doesn't exist
Hint: Did you mean "main"?
"###);
}

0 comments on commit eac7f99

Please sign in to comment.