go-task/task · error
task: cannot use --list and --list-all at the same time
Error message
task: cannot use --list and --list-all at the same time
What it means
Flag validation error raised by the Validate function after CLI parsing before task execution. It fires when both --list and --list-all are supplied; these are mutually exclusive task-listing modes (--list shows only called tasks, --list-all shows every task including internal ones), so the tool cannot decide which view to produce. Fix by passing only one of the two flags.
Source
Thrown at internal/flags/flags.go:229
if Global && Dir != "" {
return errors.New("task: You can't set both --global and --dir")
}
if Output.Name != "group" {
if Output.Group.Begin != "" {
return errors.New("task: You can't set --output-group-begin without --output=group")
}
if Output.Group.End != "" {
return errors.New("task: You can't set --output-group-end without --output=group")
}
if Output.Group.ErrorOnly {
return errors.New("task: You can't set --output-group-error-only without --output=group")
}
}
if List && ListAll {
return errors.New("task: cannot use --list and --list-all at the same time")
}
if ListJson && !List && !ListAll {
return errors.New("task: --json only applies to --list or --list-all")
}
if NoStatus && !ListJson {
return errors.New("task: --no-status only applies to --json with --list or --list-all")
}
if Nested && !ListJson {
return errors.New("task: --nested only applies to --json with --list or --list-all")
}
// Validate certificate flags
if (Cert != "" && CertKey == "") || (Cert == "" && CertKey != "") {
return errors.New("task: --cert and --cert-key must be provided together")
}View on GitHub (pinned to 385e5ad92a)
Solutions
- Add --list or --list-all alongside --json
- Remove --json if you didn't intend to list tasks
- Update scripts that expected JSON output from plain task runs
Example fix
# before task --json # after task --list --json
Defensive patterns
Strategy: validation
Validate before calling
if flags.ListJson && !flags.List && !flags.ListAll {
return errors.New("--json requires --list or --list-all")
} Try / catch
if err := flags.Validate(); err != nil {
if strings.Contains(err.Error(), "--json only applies") {
fmt.Fprintln(os.Stderr, "--json works only with --list or --list-all")
os.Exit(2)
}
return err
} Prevention
- Remember --json is a modifier for list commands, not a global output format
- Gate --json in scripts behind list intent
- Use `task --list --json` for machine-readable task lists
When it happens
Trigger: Running `task --json` (or --json with other non-list flags) so ListJson is true while both List and ListAll are false when Validate() executes.
Common situations: Scripting attempts to get JSON task output by piping a normal run with --json; assuming --json works like other tools' global output-format flags.
Understand the failure class
Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.
Related errors
- task: --json only applies to --list or --list-all
- task: --no-status only applies to --json with --list or --li
- task: You can't set both --download and --offline flags
- task: You can't set both --download and --clear-cache flags
- task: You can't set both --global and --dir
AI-assisted analysis of go-task/task@385e5ad92a (2026-09-05).
Data as JSON: /api/errors/b58ef3777fef614c.
Report an issue: GitHub.