mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 20:47:44 +02:00
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:
@ -3127,6 +3127,17 @@ fn parse_list_shape(
|
||||
// overflows with spans
|
||||
let end = if bytes.ends_with(b">") {
|
||||
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 {
|
||||
let err = ParseError::Unclosed(">".into(), span);
|
||||
return (SyntaxShape::List(Box::new(SyntaxShape::Any)), Some(err));
|
||||
|
Reference in New Issue
Block a user