Describe the bug
I find it a bit confusing how/when errors are handled by Nushell. It seems maybe my confusion was due to a bug?
How to reproduce
> # 1: Define some function that might fail partway through:
> def foo [] { echo start; ^false; echo end }
> # 2: Default behavior is to stop execution. But not very loudly. Maybe "begin" looks like good output to me?
> foo
begin
> # 3: I can force a more "loud" error with `do -c`:
> do -c { foo }
begin
Error: nu::shell::external_command
× External command failed
╭─[entry #66:1:1]
1 │ def foo [] { echo begin; ^false; echo end }
· ──┬──
· ╰── External command failed
╰────
help:
> # 4: When used in a pipe, suddenly the behavior changes. No short-circuiting OR loud failure.
> foo | $"result: ($in)" # no early exit or loud error.
result: end
> # 5: Even if I try to m force the loud failure, pipes seem to override it:
> do -c { foo } | $"result: ($in)" # ... even if we try to force it.
result: end
Expected behavior
-
My ideal behavior would be for foo to fail with the "External command failed" error in all cases without me needing to do anything special. Silent failures are a bit of a pet peeve of mine. But I think changing that behavior is a ticket all by itself, so I'm happy to set that aside for now. (But if you agree, can we open that ticket? 😊)
-
Probably need some more detailed docs on how errors are supposed to be handled so when some hapless newb like me comes across it they can figure it out. 😅 The Book has a Creating your own errors section, but doesn't mention how errors are handled by default. The do for core page documents some error handling flags, but I really can't tell from them what the behavior should be w.r.t. my foo function, or what the default behavior is. For the record, current behavior is:
~> do -i { foo }
begin
~> do -s { foo }
begin
~> do -p { foo }
begin
~> do { foo }
begin
~> do -c { foo }
begin
Error: nu::shell::external_command [etc.]
- And once the desired behavior is documented, the remaining bug is making things work that way.
Screenshots
No response
Configuration
| key |
value |
| version |
0.85.0 |
| branch |
|
| commit_hash |
|
| build_os |
macos-aarch64 |
| build_target |
aarch64-apple-darwin |
| rust_version |
rustc 1.72.0 (5680fa18f 2023-08-23) (Homebrew) |
| cargo_version |
cargo 1.72.0 (26bba4830 2023-08-26) |
| build_time |
2023-09-19 18:42:47 +00:00 |
| build_rust_channel |
release |
| allocator |
mimalloc |
| features |
dataframe, default, sqlite, trash, which, zip |
| installed_plugins |
|
Additional context
❤️ Nushell!
Describe the bug
I find it a bit confusing how/when errors are handled by Nushell. It seems maybe my confusion was due to a bug?
How to reproduce
Expected behavior
My ideal behavior would be for
footo fail with the "External command failed" error in all cases without me needing to do anything special. Silent failures are a bit of a pet peeve of mine. But I think changing that behavior is a ticket all by itself, so I'm happy to set that aside for now. (But if you agree, can we open that ticket? 😊)Probably need some more detailed docs on how errors are supposed to be handled so when some hapless newb like me comes across it they can figure it out. 😅 The Book has a Creating your own errors section, but doesn't mention how errors are handled by default. The do for core page documents some error handling flags, but I really can't tell from them what the behavior should be w.r.t. my
foofunction, or what the default behavior is. For the record, current behavior is:Screenshots
No response
Configuration
Additional context
❤️ Nushell!