go-task/task · error
task: --json only applies to --list or --list-all
Error message
task: --json only applies to --list or --list-all
What it means
Flag validation error raised by the Validate function after CLI parsing before task execution. It fires when --json is passed without either --list or --list-all; JSON formatting of task listings is only supported for those two listing modes, so the flag has no effect otherwise. Fix by adding --list or --list-all, or removing --json.
Source
Thrown at internal/flags/flags.go:233
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")
}
return nil
}
View on GitHub (pinned to 385e5ad92a)
Solutions
- Use `--json --list --no-status` (or --list-all) as the full flag set
- Remove --no-status if you don't want JSON list output
- Fix scripts so --no-status is only added when --json listing is enabled
Example fix
# before task --list --no-status # after task --list --json --no-status
Defensive patterns
Strategy: validation
Validate before calling
if flags.NoStatus && !flags.ListJson {
return errors.New("--no-status requires --json with --list or --list-all")
} Try / catch
if err := flags.Validate(); err != nil {
if strings.Contains(err.Error(), "--no-status only applies") {
fmt.Fprintln(os.Stderr, "use: task --list --json --no-status")
os.Exit(2)
}
return err
} Prevention
- Use the full combination --json --list --no-status as a unit
- Define script constants for the complete JSON-listing flag set
- Don't add --no-status for text-mode listings
When it happens
Trigger: Running `task --no-status` (or with --list/--list-all but without --json) so NoStatus is true while ListJson is false when Validate() executes.
Common situations: CI scripts passing --no-status for compact output but missing the required --json --list combination; stale documentation examples.
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: cannot use --list and --list-all at the same time
- 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/b3459a58ccb0c241.
Report an issue: GitHub.