Skip to content

Show parse-time evaluation errors on one line - #19635

Merged
fdncred merged 1 commit into
nushell:mainfrom
fdncred:parse_time_eval_error
Nov 23, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
fdncred:parse_time_eval_error

Conversation

@fdncred

@fdncred fdncred commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

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

`ShellError::wrap` turned an error from parse-time evaluation (a `const`
value, the name given to `use`/`hide`/`source`, ...) into a `ParseError`
whose message was the whole rendered report: color codes, box drawing and
source snippet. The REPL status line, the language server, `--ide-check`,
the debug adapter and `nu check --debug` all showed that report as one
message.

`wrap` now builds `ParseError::ParseTimeEval`, which keeps the report as
its message (printed errors don't change) and the evaluation error itself.
New `ParseError` methods give the one-line form:

- `headline_and_label()`: headline plus first label, moved from the
  status line
- `one_line_message()`: that line for a parse-time evaluation error, the
  usual message for every other error; used by nu-lsp, `--ide-check`,
  nu-dap and `nu check --debug`
- `one_line_span()`: the span of that label when it lies inside the
  error's span, so editors underline the part that failed

nu-mcp reports the evaluation error's own code, message, help and labels.
@github-actions github-actions Bot added A:parser Issues related to parsing A:LSP Language Server Protocol (nu-lsp) labels Nov 22, 2026
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Nov 23, 2026
@fdncred
fdncred merged commit 72286fc into nushell:main Nov 23, 2026
15 checks passed
@fdncred
fdncred deleted the parse_time_eval_error branch November 23, 2026 14:27
@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 23, 2026
fdncred added a commit that referenced this pull request Nov 23, 2026
#19645)

## Description

`repl::test_engine::const_switch_rejects_a_value_that_is_not_a_bool`
fails on main (1dc849d), and so does every PR's root test job. #19638
added the test. Two PRs merged a few minutes before it changed what the
test expects, and each of the three passed CI on its own base:

- #19634 turned on `cell-path-types`, so the parser now knows `$r.a` in
`const r = {a: 5}` is an `int`. It rejects `--chars=$r.a` with a type
mismatch and never evaluates the const.
- #19635 moved errors from parse-time evaluation out of
`ParseError::LabeledError` and into the new `ParseError::ParseTimeEval`.

The test covers the check #19638 added to const evaluation, so it needs
an argument the parser can't type. It now passes `($r | get a)`. `get`
returns `any`, so the parser lets it through and the const evaluation
rejects it. The test matches the `CantConvert` inside `ParseTimeEval`,
the same way `builtin_switch_rejects_a_value_that_is_not_a_bool` matches
its error.

## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/

Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.

Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."

If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar

This tells us the change should not appear in the changelog.

Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise

You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure

Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."

You may leave this blank until the PR is ready.
-->

## Additional notes
<!--
Optional.

Examples:
- fixes #123
- closes #456
- related #789

Anything else reviewers should know.
Remove this section if not needed.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:LSP Language Server Protocol (nu-lsp) A:parser Issues related to parsing notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant