{"record":{"id":"c1608c34ad0678be","repo":"netbirdio/netbird","slug":"cannot-specify-both-all-flag-and-state-name","errorCode":null,"errorMessage":"cannot specify both --all flag and state name","messagePattern":"cannot specify both --all flag and state name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"client/cmd/state.go","lineNumber":43,"sourceCode":"\tAliases: []string{\"ls\"},\n\tShort:   \"List all stored states\",\n\tLong:    \"Lists all registered states with their status and basic information.\",\n\tExample: \"  netbird state list\",\n\tRunE:    stateList,\n}\n\nvar stateCleanCmd = &cobra.Command{\n\tUse:   \"clean [state-name]\",\n\tShort: \"Clean stored states\",\n\tLong: `Clean specific state or all states. The daemon must not be running.\nThis will perform cleanup operations and remove the state.`,\n\tExample: `  netbird state clean dns_state\n  netbird state clean --all`,\n\tRunE: stateClean,\n\tPreRunE: func(cmd *cobra.Command, args []string) error {\n\t\t// Check mutual exclusivity between --all flag and state-name argument\n\t\tif allFlag && len(args) > 0 {\n\t\t\treturn fmt.Errorf(\"cannot specify both --all flag and state name\")\n\t\t}\n\t\tif !allFlag && len(args) != 1 {\n\t\t\treturn fmt.Errorf(\"requires a state name argument or --all flag\")\n\t\t}\n\t\treturn nil\n\t},\n}\n\nvar stateDeleteCmd = &cobra.Command{\n\tUse:   \"delete [state-name]\",\n\tShort: \"Delete stored states\",\n\tLong: `Delete specific state or all states from storage. The daemon must not be running.\nThis will remove the state without performing any cleanup operations.`,\n\tExample: `  netbird state delete dns_state\n  netbird state delete --all`,\n\tRunE: stateDelete,\n\tPreRunE: func(cmd *cobra.Command, args []string) error {\n\t\t// Check mutual exclusivity between --all flag and state-name argument","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/cmd/state.go#L25-L61","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-pasting from the command's two examples at once; shell aliases or scripts that combine the bulk and single-state forms.","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"],"exampleFix":"# before\nnetbird state clean --all dns_state\n\n# after\nnetbird state clean dns_state","handlingStrategy":"validation","validationCode":"if allFlag && len(args) > 0 {\n    return fmt.Errorf(\"cannot specify both --all flag and state name\")\n}","typeGuard":"func isCleanInvocation(all bool, args []string) bool {\n    return (all && len(args) == 0) || (!all && len(args) == 1)\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["go","cli","validation","flags"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}