Skip to content

refactor exit logic - #18389

Merged
cptpiepmatz merged 1 commit into
nushell:mainfrom
Tyarel8:refactor-exit
Jun 18, 2026
Merged

cptpiepmatz merged 1 commit into
nushell:mainfrom
Tyarel8:refactor-exit

Conversation

@Tyarel8

@Tyarel8 Tyarel8 commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Removed an exception on the repl that intercepted exit followed by an optional int and exited nushell directly. This was to drop the reedline object before exiting in order to restore the cursor (#9314), but it wouldn't work if the exit was after a pipeline, or inside a custom command, etc.

Now, the cursor restoring should happen regardless of how you call exit and it will also remove the confusing behavior when you shadow exit with a custom command, as that would be ignored when typing exit but not print test ; exit for example.

User-facing changes (Release notes)

Typing exit in the repl will no longer use a different logic and will call the exit command normally. Furthermore, any invocation of exit (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.

@Tyarel8

Tyarel8 commented Jun 13, 2026

Copy link
Copy Markdown
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
Tyarel8 marked this pull request as ready for review June 13, 2026 08:20

@cptpiepmatz cptpiepmatz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that looks good, let's give a go

@cptpiepmatz
cptpiepmatz merged commit 7ac02cf into nushell:main Jun 18, 2026
18 checks passed
@github-actions github-actions Bot added this to the v0.114.0 milestone Jun 18, 2026
@Tyarel8
Tyarel8 deleted the refactor-exit branch June 18, 2026 16:39
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Jun 22, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants