mirror of
https://github.com/go-task/task.git
synced 2026-06-11 09:51:50 +00:00
fix: improve error message when searching for Taskfile. (#2682)
This commit is contained in:
@@ -11,14 +11,17 @@ import (
|
|||||||
// TaskfileNotFoundError is returned when no appropriate Taskfile is found when
|
// TaskfileNotFoundError is returned when no appropriate Taskfile is found when
|
||||||
// searching the filesystem.
|
// searching the filesystem.
|
||||||
type TaskfileNotFoundError struct {
|
type TaskfileNotFoundError struct {
|
||||||
URI string
|
URI string
|
||||||
Walk bool
|
Walk bool
|
||||||
AskInit bool
|
AskInit bool
|
||||||
|
OwnerChange bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err TaskfileNotFoundError) Error() string {
|
func (err TaskfileNotFoundError) Error() string {
|
||||||
var walkText string
|
var walkText string
|
||||||
if err.Walk {
|
if err.OwnerChange {
|
||||||
|
walkText = " (or any of the parent directories until ownership changed)."
|
||||||
|
} else if err.Walk {
|
||||||
walkText = " (or any of the parent directories)."
|
walkText = " (or any of the parent directories)."
|
||||||
}
|
}
|
||||||
if err.AskInit {
|
if err.AskInit {
|
||||||
|
|||||||
@@ -108,10 +108,10 @@ func SearchAll(entrypoint, dir string, possibleFilenames []string) ([]string, er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
paths, err := SearchNPathRecursively(dir, possibleFilenames, -1)
|
paths, err := SearchNPathRecursively(dir, possibleFilenames, -1)
|
||||||
if err != nil {
|
// The call to SearchNPathRecursively is ambiguous and may return
|
||||||
return nil, err
|
// os.ErrPermission if its search ends, however it may have still
|
||||||
}
|
// returned valid paths. Caller may choose to ignore that error.
|
||||||
return append(entrypoints, paths...), nil
|
return append(entrypoints, paths...), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchPath will check if a file at the given path exists or not. If it does,
|
// SearchPath will check if a file at the given path exists or not. If it does,
|
||||||
@@ -188,9 +188,12 @@ func SearchNPathRecursively(path string, possibleFilenames []string, n int) ([]s
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error if we reached the root directory and still haven't found a file
|
// If the user id of the directory changes indicate a permission error, otherwise
|
||||||
// OR if the user id of the directory changes
|
// the calling code will infer an error condition based on the accumulated
|
||||||
if path == parentPath || (parentOwner != owner) {
|
// contents of paths.
|
||||||
|
if parentOwner != owner {
|
||||||
|
return paths, os.ErrPermission
|
||||||
|
} else if path == parentPath {
|
||||||
return paths, nil
|
return paths, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
11
setup.go
11
setup.go
@@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/go-task/task/v3/internal/env"
|
"github.com/go-task/task/v3/internal/env"
|
||||||
"github.com/go-task/task/v3/internal/execext"
|
"github.com/go-task/task/v3/internal/execext"
|
||||||
"github.com/go-task/task/v3/internal/filepathext"
|
"github.com/go-task/task/v3/internal/filepathext"
|
||||||
"github.com/go-task/task/v3/internal/fsext"
|
|
||||||
"github.com/go-task/task/v3/internal/logger"
|
"github.com/go-task/task/v3/internal/logger"
|
||||||
"github.com/go-task/task/v3/internal/output"
|
"github.com/go-task/task/v3/internal/output"
|
||||||
"github.com/go-task/task/v3/internal/version"
|
"github.com/go-task/task/v3/internal/version"
|
||||||
@@ -60,12 +59,10 @@ func (e *Executor) getRootNode() (taskfile.Node, error) {
|
|||||||
taskfile.WithCert(e.Cert),
|
taskfile.WithCert(e.Cert),
|
||||||
taskfile.WithCertKey(e.CertKey),
|
taskfile.WithCertKey(e.CertKey),
|
||||||
)
|
)
|
||||||
if os.IsNotExist(err) {
|
var taskNotFoundError errors.TaskfileNotFoundError
|
||||||
return nil, errors.TaskfileNotFoundError{
|
if errors.As(err, &taskNotFoundError) {
|
||||||
URI: fsext.DefaultDir(e.Entrypoint, e.Dir),
|
taskNotFoundError.AskInit = true
|
||||||
Walk: true,
|
return nil, taskNotFoundError
|
||||||
AskInit: true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -22,7 +22,13 @@ func NewFileNode(entrypoint, dir string, opts ...NodeOption) (*FileNode, error)
|
|||||||
resolvedEntrypoint, err := fsext.Search(entrypoint, dir, DefaultTaskfiles)
|
resolvedEntrypoint, err := fsext.Search(entrypoint, dir, DefaultTaskfiles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
return nil, errors.TaskfileNotFoundError{URI: entrypoint, Walk: false}
|
if entrypoint == "" {
|
||||||
|
return nil, errors.TaskfileNotFoundError{URI: entrypoint, Walk: true}
|
||||||
|
} else {
|
||||||
|
return nil, errors.TaskfileNotFoundError{URI: entrypoint, Walk: false}
|
||||||
|
}
|
||||||
|
} else if errors.Is(err, os.ErrPermission) {
|
||||||
|
return nil, errors.TaskfileNotFoundError{URI: entrypoint, Walk: true, OwnerChange: true}
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-task/task/v3/errors"
|
||||||
"github.com/go-task/task/v3/internal/fsext"
|
"github.com/go-task/task/v3/internal/fsext"
|
||||||
"github.com/go-task/task/v3/taskrc/ast"
|
"github.com/go-task/task/v3/taskrc/ast"
|
||||||
)
|
)
|
||||||
@@ -62,6 +63,9 @@ func GetConfig(dir string) (*ast.TaskRC, error) {
|
|||||||
return config, err
|
return config, err
|
||||||
}
|
}
|
||||||
entrypoints, err := fsext.SearchAll("", absDir, defaultTaskRCs)
|
entrypoints, err := fsext.SearchAll("", absDir, defaultTaskRCs)
|
||||||
|
if errors.Is(err, os.ErrPermission) {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return config, err
|
return config, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user