Skip to content

Conversation

@semihbkgr
Copy link
Contributor

@semihbkgr semihbkgr commented Dec 15, 2025

Fixes #2581

When running task in a directory without a Taskfile, the error message was showing an empty path (task: No Taskfile found at "") and missing the helpful --init suggestion. This was caused by conflicting error handling where NewFileNode() was already wrapping os.ErrNotExist as TaskfileNotFoundError, but getRootNode() was checking for os.IsNotExist(err) which failed on the wrapped error.

Solution

  1. Moved --init suggestion logic from error type to caller: Removed the AskInit field from TaskfileNotFoundError and moved the suggestion logic to getRootNode() in setup.go. This separates the concern of "what happened" (file not found) from "what to suggest to the user" (run --init), and ensures the suggestion only appears when appropriate (i.e., when running plain task without -t or -d flags, since --init ignores those flags).

  2. Fixed URI construction: Added fsext.GetSearchPath() helper to properly determine the absolute path being searched. This ensures TaskfileNotFoundError.URI always contains a meaningful path instead of an empty string.

  3. Simplified error handling: Changed getRootNode() to use errors.As() to properly detect TaskfileNotFoundError and wrap it with the --init suggestion when appropriate, instead of trying to re-wrap os.ErrNotExist.

Result

  • --init suggestion appears only when running task without flags
  • Proper "parent directories" message when doing recursive search
  • Error messages now show absolute paths

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Taskfile not found error shows empty path and missing --init suggestion

1 participant