forked from mirrors/jj
revset: add hint to innermost error
This seems more useful if aliases are nested. The innermost error usually contains the problem, and the outer errors are contexts where aliases are expanded.
This commit is contained in:
parent
a235aa51f6
commit
de1e4a39f4
2 changed files with 21 additions and 3 deletions
|
@ -405,9 +405,10 @@ impl From<RevsetEvaluationError> for CommandError {
|
|||
|
||||
impl From<RevsetParseError> 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,
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue