(ctx context.Context, node Node)
| 405 | } |
| 406 | |
| 407 | func (r *Reader) readNode(ctx context.Context, node Node) (*ast.Taskfile, error) { |
| 408 | b, err := r.readNodeContent(ctx, node) |
| 409 | if err != nil { |
| 410 | return nil, err |
| 411 | } |
| 412 | |
| 413 | var tf ast.Taskfile |
| 414 | if err := yaml.Unmarshal(b, &tf); err != nil { |
| 415 | // Decode the taskfile and add the file info the any errors |
| 416 | taskfileDecodeErr := &errors.TaskfileDecodeError{} |
| 417 | if errors.As(err, &taskfileDecodeErr) { |
| 418 | snippet := NewSnippet(b, |
| 419 | WithLine(taskfileDecodeErr.Line), |
| 420 | WithColumn(taskfileDecodeErr.Column), |
| 421 | WithPadding(2), |
| 422 | ) |
| 423 | return nil, taskfileDecodeErr.WithFileInfo(node.Location(), snippet.String()) |
| 424 | } |
| 425 | return nil, &errors.TaskfileInvalidError{URI: filepathext.TryAbsToRel(node.Location()), Err: err} |
| 426 | } |
| 427 | |
| 428 | // Check that the Taskfile is set and has a schema version |
| 429 | if tf.Version == nil { |
| 430 | return nil, &errors.TaskfileVersionCheckError{URI: node.Location()} |
| 431 | } |
| 432 | |
| 433 | // Set the taskfile/task's locations |
| 434 | tf.Location = node.Location() |
| 435 | for task := range tf.Tasks.Values(nil) { |
| 436 | // If the task is not defined, create a new one |
| 437 | if task == nil { |
| 438 | task = &ast.Task{} |
| 439 | } |
| 440 | // Set the location of the taskfile for each task |
| 441 | if task.Location.Taskfile == "" { |
| 442 | task.Location.Taskfile = tf.Location |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | return &tf, nil |
| 447 | } |
| 448 | |
| 449 | func (r *Reader) readNodeContent(ctx context.Context, node Node) ([]byte, error) { |
| 450 | if node, isRemote := node.(RemoteNode); isRemote { |
no test coverage detected