Skip to content

Task file commands with pipe (|) in them don't fail #392

Closed

Description

@brodster2

Using task version 3
MacOS and Linux

When using a task that runs a command that includes a pipe (|) the task does not fail if the first part of the command fails.

Example Taskfile.yml

version: '3'

tasks:
  pass:
    cmds:
      - exit 1 | echo "Hello"

  fail:
    cmds:
      - exit 1

Output:

task: exit 1 | echo "Hello"
Hello

task: exit 1
task: Failed to run task "fail": exit status 1

It still doesn't fail the task if I call task from a script that sets pipefail

#!/usr/bin/env bash

set -eo pipefail

task pass << This doesn't fail when it should
task fail

I have also tried:

tasks:
  pass:
    cmds:
      - set -e pipefail && exit 1 | echo "Hello"

but still get the same result

I couldn't see anything in the documentation about changing this behaviour, so I guess it's a bug?

Activity

  1. andreynering commented on Dec 5, 2020

    @andreynering
    Member

    Hi @brodster2, thanks for opening this issue!

    In my tests, the behavior of Bash and Task are the same: exit 1 | echo "Hello" prints "Hello" without failing.

    Regarding pipefail, you have a typo there: set -e pipefail does nothing, it should be set -o pipefail. When you do that, it works fine in Task as well.

    The only difference I found is that Bash support set -eo pipefail while Task doesn not understand -eo at all. If you think that is a bug, I recommend you to open an issue in the Bash interpreter library that Task uses: https://github.com/mvdan/sh . Feel free to ping me there and mention this issue if you want.

  2. Hades32 commented on May 30, 2022

    @Hades32

    @andreynering can you explain why this only works for single line scripts? I used your provided workaround successfully with cmd1 but with cmd2 it continues execution

      cmd1:
        cmds: 
        - set -o pipefail ; aws something | jq .someField
        - echo success # this never happens if aws fails
    
      cmd2:
        cmds: 
        - |
          set -e
          set -u
          set -o pipefail
          aws something | jq .someField
          echo success # happens despite error in the aws command
  3. ghostsquad commented on May 30, 2022

    @ghostsquad
    Contributor

    This is not a problem with Task directly. Please report https://github.com/mvdan/sh.

    Notice also that there are other differences in your script, not just the lack of newline characters, but also the lack of semicolons.

    This is definitely not a task specific problem though.

  4. pinpox commented on Nov 8, 2022

    @pinpox

    Is there a way to set -e; set -o pipefail for all cmd's?
    I want the task to stop if any of the cmd's fail, currently I have to set the bash options in front of everyone of them like so:

      cmd1:
        cmds: 
        - set -e -o pipefail; do-something-1 | foo
        - set -e -o pipefail; do-something-2 | bar
        - set -e -o pipefail; do-something-3 | baz

    It would be nice to have the possiblity to do the set -e -o pipefail once for all of them. I tried this:

      cmd1:
        cmds: 
        - set -e -o pipefail
        - do-something-1 | foo
        - do-something-2 | bar
        - do-something-3 | baz

    But this seems to fully ignore the first cmd.

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

    No labels
    No labels

    Type

    Fields

    No fields configured for bug.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions