go-task / task

A task runner / simpler Make alternative written in Go
https://taskfile.dev
MIT License
11.57k stars 618 forks source link

v3.39 - panic when using dynamic vars #1867

Closed antonosmond closed 1 month ago

antonosmond commented 1 month ago

In some cases, dynamic vars that worked in <= v3.38.0 result in a go panic in >= v3.39.0.

Version Info

To Reproduce

# create test yaml file
echo 'name: foobar' > example.yaml

# create taskfile
cat <<EOF > Taskfile.yaml
version: '3'
vars:
  NAME:
    sh: yq .name example.yaml
tasks:
  default: echo {{.NAME}}
EOF

The above works fine in version v3.38.0 - the NAME variable is dynamically populated with the result of the yq command and the task prints foobar as expected:

$ task --version
Task version: v3.38.0 (h1:O7kgA6BfwktXHPrheByQO46p3teKtRuq1EpGnFxNzbo=)
$ task
task: [default] echo foobar
foobar

In version v3.39.0 and greater, it panics:

$ task --version
Task version: v3.39.0 (h1:Loe6ppP1x38Puv1M2wigp91bH/garCt0vLWkJsiTWNI=)
$ task
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x28 pc=0x1007a06ec]

goroutine 1 [running]:
github.com/mikefarah/yq/v4/cmd.processStdInArgs({0x140000649c0?, 0x2, 0x2})
        github.com/mikefarah/yq/v4/cmd/utils.go:224 +0x3c
github.com/mikefarah/yq/v4/cmd.processArgs({0x140000649c0?, 0x23?, 0x0?})
        github.com/mikefarah/yq/v4/cmd/utils.go:256 +0x90
github.com/mikefarah/yq/v4/cmd.initCommand(0x14000127a68?, {0x140000649c0, 0x2, 0x2})
        github.com/mikefarah/yq/v4/cmd/utils.go:26 +0xa0
github.com/mikefarah/yq/v4/cmd.evaluateSequence(0x14000012900?, {0x140000649c0, 0x2, 0x2})
        github.com/mikefarah/yq/v4/cmd/evalute_sequence_command.go:65 +0x74
github.com/spf13/cobra.(*Command).execute(0x14000012900, {0x14000064960, 0x2, 0x2})
        github.com/spf13/cobra@v1.7.0/command.go:940 +0x5c8
github.com/spf13/cobra.(*Command).ExecuteC(0x14000012600)
        github.com/spf13/cobra@v1.7.0/command.go:1068 +0x35c
github.com/spf13/cobra.(*Command).Execute(0x1400005b450?)
        github.com/spf13/cobra@v1.7.0/command.go:992 +0x1c
main.main()
        github.com/mikefarah/yq/v4/yq.go:22 +0x1b0
task: Command "yq .name example.yaml" failed: exit status 2

Although the panic is from the yq binary, it must be something to do with the way the args are passed to the binary from go-task or the way the binary is invoked.

vmaerten commented 1 month ago

Hi!

I cannot reproduce :

image You can try to run task -v to enable the verbose mode

antonosmond commented 1 month ago

I upgraded to the same version of yq as you and now it's fine. Closing.