Skip to content

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

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

Activity

  1. Kangaxx-0 commented on Jan 6, 2023

    @Kangaxx-0
    ContributorAuthor

    Wants some insight to get this addressed in a clean fashion

  2. rgwood commented on Jan 6, 2023

    @rgwood
    Contributor

    Is this a duplicate of #7653?

  3. Kangaxx-0 commented on Jan 6, 2023

    @Kangaxx-0
    ContributorAuthor

    Is this a duplicate of #7653?

    I know you mentioned part of this in that issue, however, I could not reproduce the original #7653 . I left some investigations in this one, but feel free to close or associate it.

  4. WindSoilder commented on Jan 6, 2023

    @WindSoilder
    Contributor

    It seems that we can't figure out the difference between the them:

    1. (^false; "hello world")
    2. (^false | "hello world")
    3. ^false | "hello world"

    Because they all return the same PipelineData::ExternalStream with redirect_stdout: true.

    But when we run external command in SubExpression, redirect_stdout must be true, so we can catch output and assign result to variable.

    This is what I get from insight, but sorry that I'm not sure how to fix them properly.

  5. added
    A:error-handling
    on Jan 12, 2023
  6. WindSoilder commented on Feb 23, 2023

    @WindSoilder
    Contributor

    Suddenly I know how to solve the problem....We can check the input value after eval the last element in each pipeline..

  7. added this to the v0.77.0 milestone on Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-handling

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions