diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 99db5b70a..1512880de 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -405,9 +405,10 @@ impl From for CommandError { impl From for CommandError { fn from(err: RevsetParseError) -> Self { - let message = iter::successors(Some(&err), |e| e.origin()).join("\n"); - // Only for the top-level error as we can't attach hint to inner errors - let hint = match err.kind() { + let err_chain = iter::successors(Some(&err), |e| e.origin()); + let message = err_chain.clone().join("\n"); + // Only for the bottom error, which is usually the root cause + let hint = match err_chain.last().unwrap().kind() { RevsetParseErrorKind::NotPrefixOperator { op: _, similar_op, diff --git a/cli/tests/test_revset_output.rs b/cli/tests/test_revset_output.rs index f87a240d0..7d6bd19eb 100644 --- a/cli/tests/test_revset_output.rs +++ b/cli/tests/test_revset_output.rs @@ -228,6 +228,7 @@ fn test_function_name_hint() { 'branches(x)' = 'x' # override builtin function 'my_author(x)' = 'author(x)' # similar name to builtin function 'author_sym' = 'x' # not a function alias + 'my_branches' = 'branch()' # typo in alias "###, ); @@ -252,6 +253,22 @@ fn test_function_name_hint() { = Revset function "author_" doesn't exist Hint: Did you mean "author", "my_author"? "###); + + insta::assert_snapshot!(evaluate_err("my_branches"), @r###" + Error: Failed to parse revset: --> 1:1 + | + 1 | my_branches + | ^---------^ + | + = Alias "my_branches" cannot be expanded + --> 1:1 + | + 1 | branch() + | ^----^ + | + = Revset function "branch" doesn't exist + Hint: Did you mean "branches"? + "###); } #[test]