Skip to content

change display_error.exit_code to false#13873

Merged
fdncred merged 6 commits intonushell:mainfrom
WindSoilder:default_display_error
Oct 14, 2024
Merged

change display_error.exit_code to false#13873
fdncred merged 6 commits intonushell:mainfrom
WindSoilder:default_display_error

Conversation

@WindSoilder
Copy link
Copy Markdown
Contributor

The idea comes from @amtoine, I think it would be good to keey display_error.exit_code same value, if user is using default config or using no config file at all.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Sep 19, 2024

I think the better option is to change the rust code to be exit_code = false so it silences more errors.

@WindSoilder
Copy link
Copy Markdown
Contributor Author

Actually I don't quite sure, it seems to me that @IanManske want to make it more explicit

@IanManske
Copy link
Copy Markdown
Member

People disliked the extra error messages, so actually I think it should be false everywhere.

@NotTheDr01ds
Copy link
Copy Markdown
Contributor

@IanManske I get why you default to true when not using a config.nu, since users probably do want that extra error information when running a script.

I'm just not sure they realize where it will be useful yet. It may be that what we are seeing right now is just backlash against the verbose messages in the REPL, which is caused by having existing config.nu, of course.

@amtoine
Copy link
Copy Markdown
Member

amtoine commented Sep 21, 2024

i'm fine with either way, thanks @WindSoilder 🙏

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Sep 21, 2024

This is an example of true and false.

with true

 $env.config.display_errors.exit_code = true
 let status = try {
❯❯❯   git status
❯❯❯ } catch {|e| print -n ""}
fatal: not a git repository (or any of the parent directories): .git
Error: nu::shell::non_zero_exit_code

  × External command had a non-zero exit code
   ╭─[entry #25:2:3]
 1  let status = try {
 2    git status
   ·   ─────┬────
   ·        ╰── exited with code 128
 3  } catch {|e| print -n ""}
   ╰────
 $env.LAST_EXIT_CODE
128

with false

 $env.config.display_errors.exit_code = false
 let status = try {
❯❯❯   git status
❯❯❯ } catch {|e| print -n ""}
fatal: not a git repository (or any of the parent directories): .git
 $env.LAST_EXIT_CODE
128

my vote is for false everywhere

@WindSoilder WindSoilder marked this pull request as draft September 22, 2024 14:35
@NotTheDr01ds
Copy link
Copy Markdown
Contributor

@fdncred Isn't the fact that try isn't handling the error a separate bug?

As for the defaults, the example you give is already the default today. The only reason you are seeing the expanded errors in the REPL is because you have an outdated config.

Don't you want to see the line number the error occurred on when running it in a script?

nu script.nu
Error: nu::shell::non_zero_exit_code

  × External command had a non-zero exit code
    ╭─[/home/ntd/testing/script.nu:90:2]
 89print -n ""
 90 │ ^which foobaz
    ·  ──┬──
    ·    ╰── exited with code 1
 91 │
    ╰────

If it's false in the Rust defaults, then we lose the debugging information (line number) from the Nushell error message. This is good info when debugging a script. You typically want to know that you have an unhandled non-zero exit code in your script. (And I think a handled, via try, error shouldn't be printing the error message anyway).

We can also change the "with config" default for all users if we implement #13671. That gives us the best of both worlds:

  • Running nu script.nu skips loading the config, so it will still be true, and we'll get debugging errors
  • Running an external command from the REPL that creates a non-zero exit code will fail silently (or with the command's own error message if applicable). This would occur for all users, unless they explicitly set it to true in their own config.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Sep 23, 2024

@fdncred Isn't the fact that try isn't handling the error a separate bug?

probably

As for the defaults, the example you give is already the default today. The only reason you are seeing the expanded errors in the REPL is because you have an outdated config.

correct. i was just linking to where the code was that needed to be changed.

Don't you want to see the line number the error occurred on when running it in a script?

only when i set it to true, so it's opt-in

@fdncred fdncred changed the title change display_error.exit_code to true change display_error.exit_code to false Oct 10, 2024
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Oct 10, 2024

do you think we can get this into shape before the release?

@132ikl
Copy link
Copy Markdown
Member

132ikl commented Oct 10, 2024

Don't you want to see the line number the error occurred on when running it in a script?

only when i set it to true, so it's opt-in

You would have to set it to true in the script itself though, not just your config. I would definitely prefer if we didn't display errors in the REPL by default, but I think it would be really, really unfortunate if you have to set $env.config.display_errors.exit_code = true at the top of every script in order to make it explain what went wrong, instead of silently exiting.

If it's possible to make scripts and REPL w/o config have different default behavior, that would be perfect, but I'm not sure if it's feasible. It looks like @IanManske alluded to doing so in #13515, maybe he has some insight.

@IanManske
Copy link
Copy Markdown
Member

Yep @132ikl, that's exactly what I was thinking 😉. After, #13802, a config env var with all fields initialized is present at launch without a config file loaded1. It should be easy after this, to change a few default values in the config based on whether nushell was launched as a REPL or a script. IMO this solution is the best of both worlds.

Footnotes

  1. actually not quite, but almost. If you do $env.config = {}, then the default config value is initialized. Will be fixed later.

@WindSoilder WindSoilder deleted the default_display_error branch October 14, 2024 13:27
@WindSoilder WindSoilder restored the default_display_error branch October 14, 2024 13:27
@WindSoilder WindSoilder reopened this Oct 14, 2024
@WindSoilder WindSoilder marked this pull request as ready for review October 14, 2024 14:13
@fdncred fdncred merged commit 639bd4f into nushell:main Oct 14, 2024
@fdncred fdncred added the notes:mention Include the release notes summary in the "Hall of Fame" section label Oct 14, 2024
@hustcer hustcer added this to the v0.99.0 milestone Oct 14, 2024
fdncred pushed a commit that referenced this pull request Jan 30, 2025
# Description
This is a follow up for pr:
#13873

In that pr, I left 2 TODOs about tests, this pr is going to resolve
them.

# User-Facing Changes
NaN
# Tests + Formatting
Added 2 tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:mention Include the release notes summary in the "Hall of Fame" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants