netbirdio/netbird · warning
cannot specify both --all flag and state name
Error message
cannot specify both --all flag and state name
What it means
The `netbird state clean` command's PreRunE enforces mutual exclusivity: you may either pass exactly one state name (e.g. dns_state) or the --all/-a flag, never both. Passing both aborts before any RPC is made, so nothing is cleaned.
Source
Thrown at client/cmd/state.go:43
Aliases: []string{"ls"},
Short: "List all stored states",
Long: "Lists all registered states with their status and basic information.",
Example: " netbird state list",
RunE: stateList,
}
var stateCleanCmd = &cobra.Command{
Use: "clean [state-name]",
Short: "Clean stored states",
Long: `Clean specific state or all states. The daemon must not be running.
This will perform cleanup operations and remove the state.`,
Example: ` netbird state clean dns_state
netbird state clean --all`,
RunE: stateClean,
PreRunE: func(cmd *cobra.Command, args []string) error {
// Check mutual exclusivity between --all flag and state-name argument
if allFlag && len(args) > 0 {
return fmt.Errorf("cannot specify both --all flag and state name")
}
if !allFlag && len(args) != 1 {
return fmt.Errorf("requires a state name argument or --all flag")
}
return nil
},
}
var stateDeleteCmd = &cobra.Command{
Use: "delete [state-name]",
Short: "Delete stored states",
Long: `Delete specific state or all states from storage. The daemon must not be running.
This will remove the state without performing any cleanup operations.`,
Example: ` netbird state delete dns_state
netbird state delete --all`,
RunE: stateDelete,
PreRunE: func(cmd *cobra.Command, args []string) error {
// Check mutual exclusivity between --all flag and state-name argumentView on GitHub (pinned to 93e97f4bf1)
Solutions
- Drop either the --all flag or the state-name argument — use `netbird state clean dns_state` or `netbird state clean --all`
- Audit wrapper scripts so they choose one mode, not both
- Run `netbird state list` first to pick the exact state name you want
Example fix
# before netbird state clean --all dns_state # after netbird state clean dns_state
Defensive patterns
Strategy: validation
Validate before calling
if allFlag && len(args) > 0 {
return fmt.Errorf("cannot specify both --all flag and state name")
} Type guard
func isCleanInvocation(all bool, args []string) bool {
return (all && len(args) == 0) || (!all && len(args) == 1)
} Prevention
- Pick one mode per invocation in scripts; branch on whether a name exists
- Run `netbird state list` before clean/delete to choose the exact target
- Treat usage errors as script bugs: exit codes are nonzero even though nothing was modified
When it happens
Trigger: Running `netbird state clean --all dns_state` or `netbird state clean -a some_state`; a wrapper script that always appends --all while also forwarding a state name.
Common situations: Copy-pasting from the command's two examples at once; shell aliases or scripts that combine the bulk and single-state forms.
Related errors
- setup login request: %v
- duration must not be negative
- invalid anonymize level %q: use %q or %q
- --expiration must be a positive duration (e.g., 720h, 365d,
- at least one --artifact-pub-key-file must be provided
AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16).
Data as JSON: /api/errors/c1608c34ad0678be.
Report an issue: GitHub.