You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the most powerful features of the Elvish shell is that it throws an exception when a program exits with non-zero.
For those few programs that returns nonzero even in normal operation (e.g. diff), catching exceptions is easier than doing manual error checking every time for every line of code.
Exceptions could be utilized in other parts of the language too (throw command for usage by the programmer, type errors, etc.).
@fdncred Please read previous comments before commenting. And please take a look at how Elvish does this before contributing to the discussion. Your comment didn't help anything.
The problem with that is that non-zero exit codes from externals are not always errors.
Elvish can handle that too. I am using Elvish as a daily driver, and this functionality is one of the most useful. This is what keeps me from switching to Nushell.
Mhh we seem to properly suppress the non-zero exit code with try. But we do not return some easily digestable error, that can be processed in catch.
And ; sequences react to the non-zero exit.
/home/stefan/nushell〉try { diff }; echo test
diff: missing operand after 'diff'
diff: Try 'diff --help' for more information.
test
/home/stefan/nushell〉diff; echo test
diff: missing operand after 'diff'
diff: Try 'diff --help' for more information.
I’m not sure why do -i { … } | complete swallows the exit code, but this should be good. We just need to have more extensive documentation for 1. all these use cases and 2. the different kinds of errors do can handle, but everything should be good now!
I think it would be nice (though I don't know how the implementation would go) if do -i and do -c would preserve the exit code in some way, or if there was a separate flag that did that. My use case is that I want the numeric exit code from an external command, but don't want to use complete as it prevents streaming the stdout.
I think it would be nice (though I don't know how the implementation would go) if do -i and do -c would preserve the exit code in some way, or if there was a separate flag that did that. My use case is that I want the numeric exit code from an external command, but don't want to use complete as it prevents streaming the stdout.
tl;dr I need the streaming stdout so I can't use complete, and I need the exit code so I can't use do -i or do -c or try-catch
How do I disable this behavior?
It is super annoying in console
Please do not introduce such bad behavior as default (for some reason it is defaults to true for me despite what PR says)
Activity
fdncred commentedon Apr 27, 2022
The problem with that is that non-zero exit codes from externals are not always errors.
sholderbach commentedon Apr 27, 2022
If you want to read up on how this difficulty due to the messy reality of exit codes pops up (during nushell's development), you can check out JT's blog post on that https://www.jntrnr.com/exit-codes/
notramo commentedon Apr 28, 2022
@fdncred Please read previous comments before commenting. And please take a look at how Elvish does this before contributing to the discussion. Your comment didn't help anything.
Elvish can handle that too. I am using Elvish as a daily driver, and this functionality is one of the most useful. This is what keeps me from switching to Nushell.
https://elv.sh/ref/language.html#exception-capture
https://elv.sh/ref/language.html#try
Also, exceptions are mentioned in other parts of the documentation, search for "exception" in that page.
flying-sheep commentedon May 11, 2022
As far as I understand, this is supposed to work, see #3858
ClementNerma commentedon Feb 13, 2023
Any news on this? #3858 was closed without any advancement.
sholderbach commentedon Feb 13, 2023
Mhh we seem to properly suppress the non-zero exit code with
try. But we do not return some easily digestable error, that can be processed incatch.And
;sequences react to the non-zero exit.flying-sheep commentedon Feb 13, 2023
Great! This makes sense given these use cases:
try.For the following use case, we have
do -c!And for this last use case, we have
do -s { … } | complete:I’m not sure why
do -i { … } | completeswallows the exit code, but this should be good. We just need to have more extensive documentation for 1. all these use cases and 2. the different kinds of errorsdocan handle, but everything should be good now!Zoybean commentedon Feb 27, 2024
I think it would be nice (though I don't know how the implementation would go) if
do -ianddo -cwould preserve the exit code in some way, or if there was a separate flag that did that. My use case is that I want the numeric exit code from an external command, but don't want to usecompleteas it prevents streaming the stdout.flying-sheep commentedon Feb 27, 2024
You can use
$env.LAST_EXIT_CODEfor that I think: https://www.nushell.sh/book/stdout_stderr_exit_codes.html#exit-codeZoybean commentedon Feb 27, 2024
The example given in the book doesn't work in scripts for me - if the code is non-zero, it counts as an error and quits the script:
fdncred commentedon Feb 27, 2024
if you use
completeyou can get the exit code. I typically use-ito ignore errors.Zoybean commentedon Feb 28, 2024
@fdncred please see my earlier comment:
tl;dr I need the streaming stdout so I can't use
complete, and I need the exit code so I can't usedo -iordo -cortry-catchfdncred commentedon Feb 28, 2024
I guess we'd have to have a list of exit codes. Not sure I'm a fan of that.
Error on non-zero exit statuses (nushell#13515)
DoumanAsh commentedon Oct 10, 2024
How do I disable this behavior?
It is super annoying in console
Please do not introduce such bad behavior as default (for some reason it is defaults to true for me despite what PR says)
To fix this bug:
DoumanAsh/collectionScripts@82129bf
IanManske commentedon Oct 10, 2024
Relevant release notes are here for everyone's future reference: https://www.nushell.sh/blog/2024-09-17-nushell_0_98_0.html#non-zero-exit-codes-are-now-errors-toc
Basically, if you don't use the default config, you have to add a section to your config.
DoumanAsh commentedon Oct 10, 2024
The fact that defaults of uninitialized values is different from default config is already pointing to a bigger problem