{"record":{"id":"43fca34e7f075e4b","repo":"k3s-io/k3s","slug":"invalid-output-format-cfg-output","errorCode":null,"errorMessage":"invalid output format: {cfg.Output}","messagePattern":"invalid output format: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/kubeadm/token.go","lineNumber":35,"sourceCode":"// SetDefaults ensures that the default values are set on the token configuration.\n// These are set here, rather than in the default Token struct, to avoid\n// importing the cluster-bootstrap packages into the CLI.\nfunc SetDefaults(clx *cli.Context, cfg *cmds.Token) error {\n\tif !clx.IsSet(\"groups\") {\n\t\tcfg.Groups = *cli.NewStringSlice(NodeBootstrapTokenAuthGroup)\n\t}\n\n\tif !clx.IsSet(\"usages\") {\n\t\tcfg.Usages = *cli.NewStringSlice(bootstrapapi.KnownTokenUsages...)\n\t}\n\n\tif cfg.Output == \"\" {\n\t\tcfg.Output = \"text\"\n\t} else {\n\t\tswitch cfg.Output {\n\t\tcase \"text\", \"json\", \"yaml\":\n\t\tdefault:\n\t\t\treturn errors.New(\"invalid output format: \" + cfg.Output)\n\t\t}\n\t}\n\n\tif clx.Args().Len() > 0 {\n\t\tcfg.Token = clx.Args().Get(0)\n\t}\n\n\tif cfg.Token == \"\" {\n\t\tvar err error\n\t\tcfg.Token, err = bootstraputil.GenerateBootstrapToken()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/k3s-io/k3s/blob/6ba341e396edc16b8dcae978a7c5e3ac7ee5606e/pkg/kubeadm/token.go#L17-L53","documentation":"The kubeadm token-create style command validates its --output flag against a closed set {text, json, yaml}; an empty value defaults to text, anything else is rejected immediately before any token is generated.","triggerScenarios":"Running 'k3s token create --output=wide' or --output=table, or piping a script variable that is unset/whitespace into --output.","commonSituations":"Copy-pasting from kubectl docs where 'wide'/'name' are valid; shell defaults like OUTPUT=${OUTPUT:-table}; YAML templating that injects quotes into the value.","solutions":["Use one of: --output=text, --output=json, --output=yaml.","Omit --output entirely when plain text is desired (it is the default).","Validate the variable before passing it: case \"$OUT\" in text|json|yaml) ;; *) echo bad ;; esac."],"exampleFix":"# before\nk3s token create --output=wide\n# after\nk3s token create --output=json","handlingStrategy":"validation","validationCode":"switch cfg.Output {\ncase \"\", \"text\", \"json\", \"yaml\":\ndefault:\n    return fmt.Errorf(\"invalid output format %q (want text|json|yaml)\", cfg.Output)\n}","typeGuard":"func validOutputFormat(s string) bool {\n\tswitch s {\n\tcase \"\", \"text\", \"json\", \"yaml\":\n\t\treturn true\n\t}\n\treturn false\n}","tryCatchPattern":null,"preventionTips":["Default script variables explicitly: OUTPUT=${OUTPUT:-text}.","Do not copy --output values from kubectl docs."],"tags":["cli","validation","token"],"backgroundTag":null,"analyzedSha":"6ba341e396edc16b8dcae978a7c5e3ac7ee5606e","analyzedAt":"2026-08-15T16:27:54.286Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}