1
0
mirror of https://github.com/go-task/task.git synced 2024-12-04 10:24:45 +02:00

fix: nil schema panic (#1648)

This commit is contained in:
Pete Davison 2024-05-12 20:25:54 +01:00 committed by GitHub
parent ced3e7a579
commit f5c7472f64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 6 deletions

View File

@ -95,6 +95,15 @@ func TestEmptyTask(t *testing.T) {
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "default"}))
}
func TestEmptyTaskfile(t *testing.T) {
e := &task.Executor{
Dir: "testdata/empty_taskfile",
Stdout: io.Discard,
Stderr: io.Discard,
}
require.Error(t, e.Setup(), "e.Setup()")
}
func TestEnv(t *testing.T) {
tt := fileContentTest{
Dir: "testdata/env",

View File

@ -263,23 +263,28 @@ func (r *Reader) readNode(node Node) (*ast.Taskfile, error) {
}
}
var t ast.Taskfile
if err := yaml.Unmarshal(b, &t); err != nil {
var tf ast.Taskfile
if err := yaml.Unmarshal(b, &tf); err != nil {
return nil, &errors.TaskfileInvalidError{URI: filepathext.TryAbsToRel(node.Location()), Err: err}
}
// Check that the Taskfile is set and has a schema version
if tf.Version == nil {
return nil, &errors.TaskfileVersionCheckError{URI: node.Location()}
}
// Set the taskfile/task's locations
t.Location = node.Location()
for _, task := range t.Tasks.Values() {
tf.Location = node.Location()
for _, task := range tf.Tasks.Values() {
// If the task is not defined, create a new one
if task == nil {
task = &ast.Task{}
}
// Set the location of the taskfile for each task
if task.Location.Taskfile == "" {
task.Location.Taskfile = t.Location
task.Location.Taskfile = tf.Location
}
}
return &t, nil
return &tf, nil
}

0
testdata/empty_taskfile/Taskfile.yml vendored Normal file
View File