go-task/task · error
invalid method
Error message
invalid method
What it means
ErrInvalidMethod is a sentinel error thrown by NewSourcesChecker when the fingerprint 'method' name on a task is not one of the supported values ('timestamp' or 'checksum' or 'none'). It lets callers that only need a fingerprint value distinguish a bad method name from a checker that failed on the sources themselves. It is compared with errors.Is / require.ErrorIs in tests and wrapped with the offending method name in the message.
Source
Thrown at internal/fingerprint/sources.go:11
package fingerprint
import (
"fmt"
"github.com/go-task/task/v3/errors"
)
// ErrInvalidMethod lets callers that only need a fingerprint value tell a bad
// method name apart from a checker failing on the sources themselves.
var ErrInvalidMethod = errors.New("invalid method")
func NewSourcesChecker(method, tempDir string, dry bool) (SourcesCheckable, error) {
switch method {
case "timestamp":
return NewTimestampChecker(tempDir, dry), nil
case "checksum":
return NewChecksumChecker(tempDir, dry), nil
case "none":
return NoneChecker{}, nil
default:
return nil, fmt.Errorf(`task: %w "%s"`, ErrInvalidMethod, method)
}
}
View on GitHub (pinned to 385e5ad92a)
Solutions
- Set the task's `method:` to one of: none, checksum, timestamp (check spelling)
- If calling NewSourcesChecker directly, validate the method string against the supported set before calling
- Wrap the call and surface the wrapped method name (message contains the bad value) to find which task is at fault
- Omit `method:` entirely to use the default (checksum)
Example fix
# before (Taskfile.yml) method: sha256 # after method: checksum
Defensive patterns
Strategy: validation
Validate before calling
var validMethods = map[string]bool{"": true, "none": true, "checksum": true, "timestamp": true}
if !validMethods[method] {
return fmt.Errorf("unsupported fingerprint method %q: use none, checksum, or timestamp", method)
}
checker, err := fingerprint.NewSourcesChecker(method, tempDir, dry) Type guard
func isValidMethod(m string) bool {
switch m {
case "", "none", "checksum", "timestamp":
return true
}
return false
} Try / catch
checker, err := fingerprint.NewSourcesChecker(method, tempDir, dry)
if errors.Is(err, fingerprint.ErrInvalidMethod) {
return fmt.Errorf("task %q has an invalid method %q; use none, checksum, or timestamp", task.Name(), method)
}
if err != nil {
return err
} Prevention
- Only use the documented method values: none, checksum, timestamp
- Check Taskfile `method:` fields for typos when copying examples
- Validate user-supplied method strings before passing to NewSourcesChecker
When it happens
Trigger: Calling NewSourcesChecker with a method string other than "timestamp", "checksum", or "none" (it hits the switch's default case). Also triggered indirectly via compiledTask building a checker for a task whose `method:` field is misspelled, and by f.SourceValue / f.UpToDate in tests using an invalid method.
Common situations: Typo in a Taskfile's `method:` attribute (e.g. `methdo: checksum`, `method: sha256`), copying a Taskfile using a method name from another tool, or programmatically passing an unvalidated user-supplied method string to NewSourcesChecker.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- task: %w "%s"
- task: Included Taskfiles can't have dotenv declarations. Ple
- loop var must be a delimiter-separated string, list or a map
- task: invalid run "%s"
- task: output style %q not recognized
AI-assisted analysis of go-task/task@385e5ad92a (2026-09-05).
Data as JSON: /api/errors/ccf96b9c8c44cdc4.
Report an issue: GitHub.