Skip to content

runtime error (panic) when flattening an included Taskfile with a default task defined #1777

@mgbowman

Description

@mgbowman

I'm excited for the new flatten feature that was recently merged to main and wanted to give it a try and came across this SIGSEGV panic...

# Taskfile.yml
version: '3'
includes:
  base: 
    taskfile: Taskfile.base.yml
    flatten: true

tasks:
  foo:
    - echo "foo"
---
# Taskfile.base.yml
version: '3'
tasks:
  default: # <-- this appears to be the culprit
    - echo "bar"

This panics ...

$ task -a
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x98 pc=0x865a21]

goroutine 6 [running]:
github.com/go-task/task/v3/taskfile/ast.(*Tasks).Merge(0xc00018c5a8, {{{0xc00011c740, 0x1, 0x1}, 0xc0001fa780}}, 0xc0001b25b0, 0xc00005e700?)
        /home/vscode/go/pkg/mod/github.com/go-task/task/v3@v3.38.1-0.20240826211905-a72b65b3b23c/taskfile/ast/tasks.go:122 +0x221
github.com/go-task/task/v3/taskfile/ast.(*Taskfile).Merge(0xc00018c500, 0xc00018cf00, 0xc0001b25b0)
        /home/vscode/go/pkg/mod/github.com/go-task/task/v3@v3.38.1-0.20240826211905-a72b65b3b23c/taskfile/ast/taskfile.go:58 +0x1eb
github.com/go-task/task/v3/taskfile/ast.(*TaskfileGraph).Merge.func1()
        /home/vscode/go/pkg/mod/github.com/go-task/task/v3@v3.38.1-0.20240826211905-a72b65b3b23c/taskfile/ast/graph.go:92 +0xdc
golang.org/x/sync/errgroup.(*Group).Go.func1()
        /home/vscode/go/pkg/mod/golang.org/x/sync@v0.8.0/errgroup/errgroup.go:78 +0x56
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
        /home/vscode/go/pkg/mod/golang.org/x/sync@v0.8.0/errgroup/errgroup.go:75 +0x96

Looks like a nil pointer at taskfiles/ast/tasks.go:122


If I change the included task to bar ...

# Taskfile.base.yml
version: '3'
tasks:
  bar:
    - echo "bar"

...everything works as expected...

$ task -a
task: Available tasks for this project:
* bar:       
* foo: 

  • Task version: v3.38.1-0.20240826211905-a72b65b3b23c (h1:01ZCV3qmpxFkx17tDEDO4qQ/2uzXorCUl3lDtl56nVk=)
  • Operating system: Linux colima 6.5.0-15-generic #15-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 9 17:03:36 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
  • Experiments enabled: none

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions