mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 17:25:15 +02:00
This reverts commit dec0a2517f
.
It breaks programs like `fzf`
# Description
Fixes: #8472
Fixes: #8313
Reopen: #7690
# User-Facing Changes
_(List of all changes that impact the user experience here. This helps
us keep track of breaking changes.)_
# Tests + Formatting
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
# After Submitting
If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
@ -704,14 +704,7 @@ pub fn eval_expression_with_input(
|
||||
}
|
||||
};
|
||||
|
||||
// Note: for `table` command, it mights returns `ExternalStream with stdout`
|
||||
// whatever `redirect_output` is true or false, so we only want to consume ExternalStream
|
||||
// if relative stdout is None.
|
||||
if let PipelineData::ExternalStream { stdout: None, .. } = input {
|
||||
Ok(might_consume_external_result(input))
|
||||
} else {
|
||||
Ok((input, false))
|
||||
}
|
||||
Ok(might_consume_external_result(input))
|
||||
}
|
||||
|
||||
// Try to catch and detect if external command runs to failed.
|
||||
@ -1216,72 +1209,14 @@ pub fn eval_subexpression(
|
||||
mut input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
for pipeline in block.pipelines.iter() {
|
||||
for (expr_indx, expr) in pipeline.elements.iter().enumerate() {
|
||||
if expr_indx != pipeline.elements.len() - 1 {
|
||||
input = eval_element_with_input(engine_state, stack, expr, input, true, false)?.0;
|
||||
} else {
|
||||
// In subexpression, we always need to redirect stdout because the result is substituted to a Value.
|
||||
//
|
||||
// But we can check if external result is failed to run when it's the last expression
|
||||
// in pipeline. e.g: (^false; echo aaa)
|
||||
//
|
||||
// If external command is failed to run, it can't be convert into value, in this case
|
||||
// we throws out `ShellError::ExternalCommand`. And show it's stderr message information.
|
||||
// In the case, we need to capture stderr first during eval.
|
||||
input = eval_element_with_input(engine_state, stack, expr, input, true, true)?.0;
|
||||
if matches!(input, PipelineData::ExternalStream { .. }) {
|
||||
input = check_subexp_substitution(input)?;
|
||||
}
|
||||
}
|
||||
for expr in pipeline.elements.iter() {
|
||||
input = eval_element_with_input(engine_state, stack, expr, input, true, false)?.0
|
||||
}
|
||||
}
|
||||
|
||||
Ok(input)
|
||||
}
|
||||
|
||||
fn check_subexp_substitution(mut input: PipelineData) -> Result<PipelineData, ShellError> {
|
||||
let consume_result = might_consume_external_result(input);
|
||||
input = consume_result.0;
|
||||
let failed_to_run = consume_result.1;
|
||||
if let PipelineData::ExternalStream {
|
||||
stdout,
|
||||
stderr,
|
||||
exit_code,
|
||||
span,
|
||||
metadata,
|
||||
trim_end_newline,
|
||||
} = input
|
||||
{
|
||||
let stderr_msg = match stderr {
|
||||
None => "".to_string(),
|
||||
Some(stderr_stream) => stderr_stream.into_string().map(|s| s.item)?,
|
||||
};
|
||||
if failed_to_run {
|
||||
Err(ShellError::ExternalCommand {
|
||||
label: "External command failed".to_string(),
|
||||
help: stderr_msg,
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
// we've captured stderr message, but it's running success.
|
||||
// So we need to re-print stderr message out.
|
||||
if !stderr_msg.is_empty() {
|
||||
eprintln!("{stderr_msg}");
|
||||
}
|
||||
Ok(PipelineData::ExternalStream {
|
||||
stdout,
|
||||
stderr: None,
|
||||
exit_code,
|
||||
span,
|
||||
metadata,
|
||||
trim_end_newline,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
Ok(input)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eval_variable(
|
||||
engine_state: &EngineState,
|
||||
stack: &Stack,
|
||||
|
Reference in New Issue
Block a user