mirror of
https://github.com/nushell/nushell.git
synced 2026-11-26 11:35:37 +08:00
## Description
When evaluation fails at parse time, as in `hide $env.bar` or `const x =
[] | first --strict`, `ShellError::wrap` made a `ParseError` whose
message was the whole rendered report, with box drawing, source snippet
and color codes. Everything that shows an error as one line got that
report. The REPL status line printed it with each line break as a
literal `\n`. The language server, `nu --ide-check`, the debug adapter
and `nu check --debug` passed it on as the message.
`wrap` now builds a new `ParseError::ParseTimeEval`. Its message is
still the report, so printed errors don't change, but it also keeps the
evaluation error. The one-line places show that error's headline and
first label. Editors underline the label's span instead of the whole
value. The MCP server gets the evaluation error's own code, message,
help and labels.
## User-facing changes (Release notes)
- The REPL status line no longer crams a whole error report onto one row
for errors from parse-time evaluation, such as `hide $env.bar`. It shows
`✗ Not a constant: Value is not a parse-time constant`.
- The language server, `nu --ide-check`, the debug adapter and `nu check
--debug` show these errors as one line. Editors underline the part that
failed, such as `into int` in `const d = ('abc' | into int)`.
- The MCP server reports these errors with the evaluation error's own
code, message, help and labels.
## Additional notes
30 lines
787 B
Rust
30 lines
787 B
Rust
use crate::repl::tests::{TestResult, test_ide_contains};
|
|
|
|
#[test]
|
|
fn parser_recovers() -> TestResult {
|
|
test_ide_contains(
|
|
"3 + \"bob\"\nlet x = \"fred\"\n",
|
|
&["--ide-check", "5"],
|
|
"\"typename\":\"string\"",
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn parse_time_eval_error_message_is_one_line() -> TestResult {
|
|
test_ide_contains(
|
|
"hide $env.bar\n",
|
|
&["--ide-check", "5"],
|
|
"\"message\":\"Not a constant: Value is not a parse-time constant\"",
|
|
)
|
|
}
|
|
|
|
/// The span is the evaluation error's own label, `into int`, not the whole value.
|
|
#[test]
|
|
fn parse_time_eval_error_points_at_the_cause() -> TestResult {
|
|
test_ide_contains(
|
|
"const d = ('abc' | into int)\n",
|
|
&["--ide-check", "5"],
|
|
"\"span\":{\"start\":19,\"end\":27}",
|
|
)
|
|
}
|