Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brodster2 opened this issue Oct 27, 2020 · 5 comments
Closed

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

brodster2 opened this issue Oct 27, 2020 · 5 comments
Labels
type: bug Something not working as intended.

Comments

@brodster2
Copy link

brodster2 commented Oct 27, 2020

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?

@andreynering andreynering added the type: bug Something not working as intended. label Dec 5, 2020
@andreynering
Copy link
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.

@Hades32
Copy link

Hades32 commented May 30, 2022

@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

@ghostsquad
Copy link
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.

@pinpox
Copy link

pinpox commented Nov 8, 2022

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.

@ghost
Copy link

ghost commented Nov 8, 2022

Look into #908. All commands run in isolation so the variable is not set in all cmds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something not working as intended.
Projects
None yet
Development

No branches or pull requests

5 participants