MCPcopy
hub / github.com/go-task/task / readNode

Method readNode

taskfile/reader.go:407–447  ·  view source on GitHub ↗
(ctx context.Context, node Node)

Source from the content-addressed store, hash-verified

405}
406
407func (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
449func (r *Reader) readNodeContent(ctx context.Context, node Node) ([]byte, error) {
450 if node, isRemote := node.(RemoteNode); isRemote {

Callers 1

includeMethod · 0.95

Calls 11

readNodeContentMethod · 0.95
WithFileInfoMethod · 0.95
StringMethod · 0.95
AsFunction · 0.92
TryAbsToRelFunction · 0.92
NewSnippetFunction · 0.85
WithLineFunction · 0.85
WithColumnFunction · 0.85
WithPaddingFunction · 0.85
LocationMethod · 0.65
ValuesMethod · 0.45

Tested by

no test coverage detected