fix unhelpful error message with extra characters in list annotations (#8619)
# Description with such a line ```nu def err [list: list<>extra] {} ``` this pr changes the error message from ```nu Error: nu::parser::unclosed_delimiter × Unclosed delimiter. ╭─[entry #69:1:1] 1 │ def err [list: list<>extra] {} · ─────┬───── · ╰── unclosed > ╰──── ``` to ```nu × Extra characters in the parameter name. ╭─[entry #69:1:1] 1 │ def err [list: list<>extra] {} · ──┬── · ╰── extra characters ╰──── ```
This commit is contained in:
parent
d9a888528a
commit
86ae27b0c1
|
@ -3127,6 +3127,17 @@ fn parse_list_shape(
|
||||||
// overflows with spans
|
// overflows with spans
|
||||||
let end = if bytes.ends_with(b">") {
|
let end = if bytes.ends_with(b">") {
|
||||||
span.end - 1
|
span.end - 1
|
||||||
|
// extra characters after the >
|
||||||
|
} else if bytes.contains(&b'>') {
|
||||||
|
let angle_start = bytes.split(|it| it == &b'>').collect::<Vec<_>>()[0].len() + 1;
|
||||||
|
let span = Span::new(span.start + angle_start, span.end);
|
||||||
|
|
||||||
|
let err = ParseError::LabeledError(
|
||||||
|
"Extra characters in the parameter name".into(),
|
||||||
|
"extra characters".into(),
|
||||||
|
span,
|
||||||
|
);
|
||||||
|
return (SyntaxShape::Any, Some(err));
|
||||||
} else {
|
} else {
|
||||||
let err = ParseError::Unclosed(">".into(), span);
|
let err = ParseError::Unclosed(">".into(), span);
|
||||||
return (SyntaxShape::List(Box::new(SyntaxShape::Any)), Some(err));
|
return (SyntaxShape::List(Box::new(SyntaxShape::Any)), Some(err));
|
||||||
|
|
|
@ -125,3 +125,10 @@ fn list_annotations_with_default_val_2() -> TestResult {
|
||||||
let expected = "Default value wrong type";
|
let expected = "Default value wrong type";
|
||||||
fail_test(input, expected)
|
fail_test(input, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn list_annotations_with_extra_characters() -> TestResult {
|
||||||
|
let input = "def run [list: list<int>extra] {$list | length}; run [1 2 3]";
|
||||||
|
let expected = "Extra characters in the parameter name";
|
||||||
|
fail_test(input, expected)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user