Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make better messages for incomplete string #12868

Merged
merged 2 commits into from
May 15, 2024

Conversation

WindSoilder
Copy link
Collaborator

@WindSoilder WindSoilder commented May 14, 2024

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.

Copy link
Member

@IanManske IanManske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think this looks good. Just one note below.

crates/nu-parser/src/lex.rs Outdated Show resolved Hide resolved
@IanManske IanManske added the pr:errors This PR improves our error messages label May 15, 2024
Co-authored-by: Ian Manske <ian.manske@pm.me>
@IanManske
Copy link
Member

Thanks, the error messages are much better now!

@IanManske IanManske merged commit 155934f into nushell:main May 15, 2024
15 checks passed
@hustcer hustcer added this to the v0.94.0 milestone May 15, 2024
FilipAndersson245 pushed a commit to FilipAndersson245/nushell that referenced this pull request May 18, 2024
# Description
Fixes: nushell#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>
@WindSoilder WindSoilder deleted the incomplete_str branch May 23, 2024 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:errors This PR improves our error messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad record with unclosing quotes cause unhelpful error messages (need better error messages)
3 participants