diff --git a/cmd/task/task.go b/cmd/task/task.go index d5f2b7baf0..bab438ca30 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -115,6 +115,10 @@ func run() error { task.WithVersionCheck(true), ) if err := e.Setup(); err != nil { + if errors.Is(err, errors.TaskfileNotFoundError{}) { + return errors.New("No supported taskfile was found: " + + "please check the documentation for a list of supported file names.") + } return err } diff --git a/errors/errors_taskfile.go b/errors/errors_taskfile.go index a2f0bad790..e67b7bcb1f 100644 --- a/errors/errors_taskfile.go +++ b/errors/errors_taskfile.go @@ -27,6 +27,14 @@ func (err TaskfileNotFoundError) Code() int { return CodeTaskfileNotFound } +func (err TaskfileNotFoundError) Is(target error) bool { + _, ok := target.(TaskfileNotFoundError) + if ok { + return true + } + return false +} + // TaskfileAlreadyExistsError is returned on creating a Taskfile if one already // exists. type TaskfileAlreadyExistsError struct{} diff --git a/taskfile/node_file.go b/taskfile/node_file.go index aa35437cb6..0b6d8e5dc0 100644 --- a/taskfile/node_file.go +++ b/taskfile/node_file.go @@ -2,10 +2,12 @@ package taskfile import ( "io" + "io/fs" "os" "path/filepath" "strings" + "github.com/go-task/task/v3/errors" "github.com/go-task/task/v3/internal/execext" "github.com/go-task/task/v3/internal/filepathext" "github.com/go-task/task/v3/internal/fsext" @@ -22,6 +24,16 @@ func NewFileNode(entrypoint, dir string, opts ...NodeOption) (*FileNode, error) base := NewBaseNode(dir, opts...) entrypoint, base.dir, err = fsext.Search(entrypoint, base.dir, defaultTaskfiles) if err != nil { + if errors.Is(err, os.ErrNotExist) { + // We include the path in the error if one exists + var pathErr *fs.PathError + if errors.As(err, &pathErr) { + return nil, &errors.TaskfileNotFoundError{ + URI: pathErr.Path, + } + } + return nil, &errors.TaskfileNotFoundError{} + } return nil, err } return &FileNode{