Repository navigation
refactor exit logic - #18389
Merged
Merged
refactor exit logic#18389
Conversation
Contributor
Author
|
I have been using nushell with this pr for a few days to make sure there aren't any issues tests are not catching and I haven't found any so far. Please let me now if there are any problems. |
Tyarel8
marked this pull request as ready for review
June 13, 2026 08:20
cptpiepmatz
approved these changes
Jun 18, 2026
cptpiepmatz
left a comment
Member
There was a problem hiding this comment.
I think that looks good, let's give a go
fdncred
added a commit
that referenced
this pull request
Nov 12, 2026
…19467) ## Description A stream carries a failure as an item, so a command that read that item and then dropped it also dropped the failure. `last`, `get 2`, `skip 1` and others returned a normal result with exit code 0. This was the gap #16738 and #18976 closed for collecting and for `length`, `columns` and `is-empty`. `exit` makes it worse. Since #18389 (0.114.0) `exit` travels as an error instead of ending the process, so the same commands discarded it and the script kept running. 0.113.1 exits 7 on the commands below, and 0.114.0 carries on with exit code 0. Commands that read and drop an item now raise its error or pass it along, and commands that bury an item in a record or list now pass the error along instead. `;` no longer ignores an error returned as a single value. A closure is never handed an `exit`, because `catch` can't handle one and the closure could ignore it. `do --ignore-errors` no longer ignores `exit`. Items that never ran stay unevaluated, so `first` and `take` are as lazy as before. ## User-facing changes (Release notes) - An error in a stream is no longer lost when a command drops that item. This covers `last`, `get`, cell paths on a stream, `skip`, `skip while`, `skip until`, `take while`, `take until`, `select`, `drop`, `drop nth`, `slice`, `every`, `update`, `upsert`, `window`, `lines`, `zip` and `to text`. - `enumerate`, `wrap`, `zip`, `chunks`, `chunk-by`, `window` and `split list` no longer hide a stream error inside the record or list they build. - An external now reports an error or `exit` in its input once it finishes, so `boom | to text | ^cat` raises `boom` and `try` can catch it. `do --ignore-errors` still ignores the error, but not `exit`. - A closure that returns an error value now counts as failing in `take while`, `take until`, `skip while`, `skip until`, `chunk-by`, `split list` and `where`, where it used to count as `false`. - `exit` inside a closure always ends the script again, whichever command consumes the stream, and `do --ignore-errors` no longer ignores it. - `;` no longer discards an error returned as a single value, and `catch` now sees errors from `first` and `last`. ### Breaking Changes - a closure that fails in `take while`, `take until`, `skip while`, `skip until`, `chunk-by` or `split list` now raises its error, as `where` already does. It used to count as `false`, so `[{a: 1} {b: 2}] | take while {|r| $r.a == 1 }` returned the first row and now reports the missing column. Use `$r.a?` for optional columns. - a script that relied on `last`, `skip` or similar to get past an error now fails. To handle a failed item, use `each {|row| try { $row | ignore; $row } catch { ... } }`. - `reverse`, `shuffle`, `sort-by`, `drop` and `last` now raise an error item instead of keeping it among the rows, so that `try` form has to come before them. - `to text` now raises an error instead of writing its debug form into the text, and `each {|y| $y; 'ok' }` raises an error input instead of discarding it at the `;`. ## Additional notes Closes #19463
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Removed an exception on the repl that intercepted
exitfollowed by an optional int and exited nushell directly. This was todropthe reedline object before exiting in order to restore the cursor (#9314), but it wouldn't work if theexitwas after a pipeline, or inside a custom command, etc.Now, the cursor restoring should happen regardless of how you call
exitand it will also remove the confusing behavior when you shadowexitwith a custom command, as that would be ignored when typingexitbut notprint test ; exitfor example.User-facing changes (Release notes)
Typing
exitin the repl will no longer use a different logic and will call theexitcommand normally. Furthermore, any invocation ofexit(e.g. inside a keybind of custom command) will restore the terminal cursor to the state it was before rather than only in the aforementioned case.