Skip to content

fix: use errors.As to detect TaskfileNotFoundError in getRootNode#2688

Open
railgun-0402 wants to merge 1 commit intogo-task:mainfrom
railgun-0402:feature/task-not-found-err-repair
Open

fix: use errors.As to detect TaskfileNotFoundError in getRootNode#2688
railgun-0402 wants to merge 1 commit intogo-task:mainfrom
railgun-0402:feature/task-not-found-err-repair

Conversation

@railgun-0402
Copy link

Summary

  • Fix regression where task shows No Taskfile found at "" instead of the full error message with path and --init suggestion

Problem

When running task in a directory without a Taskfile, NewFileNode() in node_file.go wraps os.ErrNotExist into a TaskfileNotFoundError before returning. In getRootNode() (setup.go), the
error check uses os.IsNotExist(err), which fails to match the already-wrapped error. As a result, the enriched error (with the correct path, Walk: true, and AskInit: true) is never constructed,
and the incomplete TaskfileNotFoundError from NewFileNode() is returned as-is.

Fix

Replace os.IsNotExist(err) with errors.As(err, &taskfileNotFoundErr) so that the wrapped TaskfileNotFoundError is properly detected.

Before: task: No Taskfile found at ""
After: task: No Taskfile found at "/path/to/dir" (or any of the parent directories). Run task --init to create a new Taskfile.

Closes #2581

@railgun-0402
Copy link
Author

Ping for review 🙏
This is a small fix (+2/-1) for the regression described in #2581.

Repro: run task in a directory without a Taskfile (and none in parent dirs).

  • Before: task: No Taskfile found at ""
  • After: task: No Taskfile found at "/path/to/dir" (or any of the parent directories). Run \task --init` ... Whyerrors.As: NewFileNode()wraps the originalos.ErrNotExistintoTaskfileNotFoundError, so os.IsNotExist(err)doesn’t match anymore.

**Local check:**go test ./...` ✅ (and/or mention any specific command you ran)

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