nushell/crates/nu-protocol/src
WindSoilder c371d1a535
fix exit_code handling when running a scripts with ctrlc (#11466)
# Description
Fixes: #11394

When run `^sleep 3` we have an `exit_code ListStream`, and when we press
ctrl-c, this `ListStream` will return None. But it's not expected,
because `exit_code` sender in `run_external` always send an exit code
out.

This pr is trying to fix the issue by introducing a `first_guard` into
ListStream, it will always generate a value from underlying stream if
`first_guard` is true, so it's guarantee to have at least one value to
return.

And the pr also do a little refactor, which makes use of
`ListStream::from_stream` rather than construct it manually.

# User-Facing Changes
## Before
```
> nu -c "^sleep 3"  # press ctrl-c
> echo $env.LAST_EXIT_CODE
0
```

## After
```
> nu -c "^sleep 3"  # press ctrl-c
> echo $env.LAST_EXIT_CODE
255
```

# Tests + Formatting
None, sorry that I don't think it's easy to test the ctrlc behavior.

# After Submitting
None
2024-01-30 22:41:14 +08:00
..
ast Unify glob behavior on open, rm, cp-old, mv, umv, cp and du commands (#11621) 2024-01-26 21:57:35 +08:00
config Add CLI flag to disable history (#11550) 2024-01-17 09:40:59 -06:00
engine Add CLI flag to disable history (#11550) 2024-01-17 09:40:59 -06:00
value fix exit_code handling when running a scripts with ctrlc (#11466) 2024-01-30 22:41:14 +08:00
alias.rs Refactor scope commands (#10023) 2023-08-17 11:58:38 +03:00
cli_error.rs Refactor and fix Config<->Value mechanism (#10896) 2023-11-08 20:31:30 +01:00
did_you_mean.rs Improve case insensitivity consistency (#10884) 2023-11-08 23:58:54 +01:00
eval_base.rs Unify glob behavior on open, rm, cp-old, mv, umv, cp and du commands (#11621) 2024-01-26 21:57:35 +08:00
eval_const.rs Unify glob behavior on open, rm, cp-old, mv, umv, cp and du commands (#11621) 2024-01-26 21:57:35 +08:00
example.rs remove unused imports: Deserialize, Serialize compiler warning for nu-protocol/src/example.rs (#8514) 2023-03-18 11:45:12 -07:00
exportable.rs Module: support defining const and use const variables inside of function (#9773) 2023-08-01 07:09:52 +08:00
id.rs Add virtual path abstraction layer (#9245) 2023-05-23 23:48:50 +03:00
lev_distance.rs Suggest existing variables on not found (#8902) 2023-05-02 18:17:14 +03:00
lib.rs Deprecate --flag: bool in custom command (#11365) 2023-12-21 10:07:08 +01:00
module.rs Error on use path item1 item2, if item1 is not a module (#11183) 2023-12-05 11:38:45 +01:00
parse_error.rs Evaluate string interpolation at parse time (#11562) 2024-01-22 09:13:48 +02:00
parse_warning.rs Deprecate --flag: bool in custom command (#11365) 2023-12-21 10:07:08 +01:00
pipeline_data.rs fix exit_code handling when running a scripts with ctrlc (#11466) 2024-01-30 22:41:14 +08:00
plugin_signature.rs Rename main to script name when running scripts (#9948) 2023-08-12 05:58:49 +12:00
shell_error.rs Unify glob behavior on open, rm, cp-old, mv, umv, cp and du commands (#11621) 2024-01-26 21:57:35 +08:00
signature.rs Move history into their own module (#11308) 2023-12-15 13:17:12 +01:00
span.rs Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
syntax_shape.rs Unify glob behavior on open, rm, cp-old, mv, umv, cp and du commands (#11621) 2024-01-26 21:57:35 +08:00
ty.rs adjust some commansd input_output type (#11436) 2024-01-15 16:58:26 +08:00
util.rs Convert more ShellError variants to named fields (#11173) 2023-11-28 06:43:51 -06:00
variable.rs Fix broken constants in scopes (#9679) 2023-07-14 00:02:05 +03:00