Skip to content

Add default error codes#16166

Merged
Bahex merged 5 commits intonushell:mainfrom
132ikl:default-error-code
Jul 15, 2025
Merged

Add default error codes#16166
Bahex merged 5 commits intonushell:mainfrom
132ikl:default-error-code

Conversation

@132ikl
Copy link
Copy Markdown
Member

@132ikl 132ikl commented Jul 13, 2025

Description

Before this PR, errors without error codes are printed somewhat strangely, with the × and the description being printed on the same line as the Error: text:
image

This PR adds a default error code for the different error types:
image

While maybe not as informative as a proper error code, it makes GenericErrors and other things which don't have error codes look a lot nicer.

It would be nicer if we could just set diagnostic(code: "nu::shell::error") at the top of ShellError, but unfortunately you can't set a "default" at the enum level and then override it in the variants. @cptpiepmatz mentioned he might change miette's derive macro to accommodate this, in that case we can switch the approach here.

User-Facing Changes

  • Errors without error codes now have a default error code corresponding to from which part of Nushell the error occurred (shell, parser, compile, etc)

Tests + Formatting

N/A

After Submitting

N/A

@132ikl 132ikl added the deprecated:pr-errors Deprecated: use A:error-handling, A:error-unhelpful, or A:error-silent-fail instead label Jul 13, 2025
@Bahex
Copy link
Copy Markdown
Member

Bahex commented Jul 14, 2025

Errors thrown with error make look so much better with this PR, it immediately raises the user experience of std too

@Bahex Bahex merged commit 4ed522d into nushell:main Jul 15, 2025
16 checks passed
@github-actions github-actions bot added this to the v0.106.0 milestone Jul 15, 2025
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Aug 25, 2025
# Description
Before this PR, errors without error codes are printed somewhat
strangely, with the `×` and the description being printed on the same
line as the `Error:` text:

    Error:   × Invalid literal
       ╭─[entry #1:1:2]
     1 │ "\z"
       ·  ─┬─
       ·   ╰── unrecognized escape after '\' in string
       ╰────


This PR adds a default error code for the different error types:

    Error: nu::parser::error

      × Invalid literal
       ╭─[entry #1:1:2]
     1 │ "\z"
       ·  ─┬─
       ·   ╰── unrecognized escape after '\' in string
       ╰────

While maybe not as informative as a proper error code, it makes
`GenericError`s and other things which don't have error codes look a lot
nicer.

It would be nicer if we could just set `diagnostic(code:
"nu:🐚:error")` at the top of `ShellError`, but unfortunately you
can't set a "default" at the `enum` level and then override it in the
variants. @cptpiepmatz mentioned he might change miette's derive macro
to accommodate this, in that case we can switch the approach here.

# User-Facing Changes
* Errors without error codes now have a default error code corresponding
to from which part of Nushell the error occurred (shell, parser,
compile, etc)

---------

Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deprecated:pr-errors Deprecated: use A:error-handling, A:error-unhelpful, or A:error-silent-fail instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants