-
-
Notifications
You must be signed in to change notification settings - Fork 774
Description
Description
When running task in a directory without a Taskfile (and no Taskfile in parent directories), the error message displays an empty path and is missing the helpful suggestion to run task --init:
task: No Taskfile found at ""
The error message does not include:
(or any of the parent directories)Runtask --initto create a new Taskfile.
This is a regression from previous versions where the error message properly displayed the directory path being searched and included a suggestion to run task --init.
Previous Behavior
In previous versions, the error message was informative and helpful:
task: No Taskfile found at "/path/to/directory" (or any of the parent directories). Run `task --init` to create a new Taskfile.
Root Cause
The issue is caused by conflicting error handling between NewFileNode() and getRootNode():
In taskfile/node_file.go, NewFileNode() was already wrapping os.ErrNotExist with TaskfileNotFoundError:
func NewFileNode(entrypoint, dir string, opts ...NodeOption) (*FileNode, error) {
resolvedEntrypoint, err := fsext.Search(entrypoint, dir, DefaultTaskfiles)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, errors.TaskfileNotFoundError{URI: entrypoint, Walk: false}
}
return nil, err
}
// ...
}In setup.go, getRootNode() was checking for os.IsNotExist(err) to wrap the error:
func (e *Executor) getRootNode() (taskfile.Node, error) {
node, err := taskfile.NewRootNode(e.Entrypoint, e.Dir, e.Insecure, e.Timeout)
if os.IsNotExist(err) { // This check fails because err is already TaskfileNotFoundError
return nil, errors.TaskfileNotFoundError{
URI: fsext.DefaultDir(e.Entrypoint, e.Dir),
Walk: true,
AskInit: true,
}
}
// ...
}The problem: os.IsNotExist(err) returns false when err is TaskfileNotFoundError (not os.ErrNotExist), so the error is returned as-is with an empty or incorrect URI and without the AskInit suggestion.
Steps to Reproduce
- Navigate to an empty directory (with no Taskfile in parent directories)
- Run
task - Observe the error message shows an empty path and doesn't suggest
task --init
Version
main
Operating system
macOS
Experiments Enabled
No response