Skip to content

SubExpression with external command failure does not stop command running #7690

@Kangaxx-0

Description

@Kangaxx-0

Describe the bug

Say we have a SubExpression (^false;"hello,world!"), the first part of external command returns 1 which is a failure, but nu still prints hello, world!

The issue is in eval_subexpression function, it passes redirect_stdout = true, a few actions happens next:

image

  • When nu returns ExternalStream, the stdout is a RawStream instead of None

image

  • Nu tries to catch external stream exit status, but returns failure = false because above rawstream output

image

Also, inside the eval_subexpression function, it does not deal with early return if external command fails.

I did try to tweak how redirect_stdout works, my change fixes this one but introduces another bug -> stdout will not be able to redirect anymore, nu choose Stdio:piped() and Stdio::inherit based on edirect_stdout

This seems not a recent regression, I saw the same behavior on 0.68 commit tag

How to reproduce

Run (^false;"hello,world!")

Expected behavior

Do not print hello,world!

Screenshots

No response

Configuration

Clipboard does not work, so pasting a screenshot

image

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-handlingHow errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions