mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 03:37:51 +02:00
make better messages for incomplete string (#12868)
# Description Fixes: #12795 The issue is caused by an empty position of `ParseError::UnexpectedEof`. So no detailed message is displayed. To fix the issue, I adjust the start of span to `span.end - 1`. In this way, we can make sure that it never points to an empty position. After lexing item, I also reorder the unclosed character checking . Now it will be checking unclosed opening delimiters first. # User-Facing Changes After this pr, it outputs detailed error message for incomplete string when running scripts. ## Before ``` ❯ nu -c "'ab" Error: nu::parser::unexpected_eof × Unexpected end of code. ╭─[source:1:4] 1 │ 'ab ╰──── > ./target/debug/nu -c "r#'ab" Error: nu::parser::unexpected_eof × Unexpected end of code. ╭─[source:1:6] 1 │ r#'ab ╰──── ``` ## After ``` > nu -c "'ab" Error: nu::parser::unexpected_eof × Unexpected end of code. ╭─[source:1:3] 1 │ 'ab · ┬ · ╰── expected closing ' ╰──── > ./target/debug/nu -c "r#'ab" Error: nu::parser::unexpected_eof × Unexpected end of code. ╭─[source:1:5] 1 │ r#'ab · ┬ · ╰── expected closing '# ╰──── ``` # Tests + Formatting Added some tests for incomplete string. --------- Co-authored-by: Ian Manske <ian.manske@pm.me>
This commit is contained in:
@ -154,6 +154,18 @@ fn raw_string_inside_closure() -> TestResult {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incomplete_raw_string() -> TestResult {
|
||||
fail_test("r#abc", "expected '")
|
||||
fn incomplete_string() -> TestResult {
|
||||
fail_test("r#abc", "expected '")?;
|
||||
fail_test("r#'bc", "expected closing '#")?;
|
||||
fail_test("'ab\"", "expected closing '")?;
|
||||
fail_test("\"ab'", "expected closing \"")?;
|
||||
fail_test(
|
||||
r#"def func [] {
|
||||
{
|
||||
"A": ""B" # <- the quote is bad
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"expected closing \"",
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user