{"record":{"id":"32dac37128435099","repo":"hashicorp/nomad","slug":"headers-must-be-in-the-form-key-value-but-found","errorCode":null,"errorMessage":"Headers must be in the form 'Key: Value' but found: %q","messagePattern":"Headers must be in the form 'Key: Value' but found: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_api.go","lineNumber":487,"sourceCode":"}\n\n// headerFlags is a flag.Value implementation for collecting multiple -H flags.\ntype headerFlags struct {\n\theaders http.Header\n}\n\nfunc newHeaderFlags() *headerFlags {\n\treturn &headerFlags{\n\t\theaders: make(http.Header),\n\t}\n}\n\nfunc (*headerFlags) String() string { return \"\" }\n\nfunc (h *headerFlags) Set(v string) error {\n\tparts := strings.SplitN(v, \":\", 2)\n\tif len(parts) != 2 {\n\t\treturn fmt.Errorf(\"Headers must be in the form 'Key: Value' but found: %q\", v)\n\t}\n\n\th.headers.Add(parts[0], strings.TrimSpace(parts[1]))\n\treturn nil\n}\n","sourceCodeStart":469,"sourceCodeEnd":493,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_api.go#L469-L493","documentation":"This error is returned by headerFlags.Set, the pflag parser hook for the -http-addr-style repeatable header flag on operator commands. The flag expects each occurrence to be an HTTP header literal of the form 'Key: Value' with a colon separating key and value; the value is split on the first colon via strings.SplitN(v, \":\", 2). If no colon is present the input cannot be interpreted as a header and this error aborts flag parsing.","triggerScenarios":"Passing a header value without a colon to the repeatable header flag, e.g. `consul debug -header=Authorization` or `-header BearerToken`, instead of `-header=Authorization: Bearer xyz`. A typo'd flag such as `-headerfoo:bar` can also land here as the flag's Set value.","commonSituations":"Copy-pasting a bare token into the header flag; forgetting the space after the colon is fine but forgetting the colon entirely is not; scripting the command where an env var holding 'Key: Value' was empty or truncated to just the key; shell quoting stripping the colon.","solutions":["Rewrite the flag value to include a colon separating key and value: -header=\"Authorization: Bearer <token>\"","Quote the whole argument so the shell does not split or mangle it: -header=\"X-Consul-Token: abc123\"","Verify the env variable/secret you interpolate actually contains the 'Key: Value' form, not just the value","Each header needs its own -header flag occurrence; do not pack multiple headers into one value"],"exampleFix":"// before\nconsul operator debug -header=Authorization\n// after\nconsul operator debug -header=\"Authorization: Bearer eyJhbGciOi...\"","handlingStrategy":"validation","validationCode":"func validHeader(s string) bool {\n\treturn strings.Contains(s, \":\") && strings.SplitN(s, \":\", 2)[0] != \"\"\n}\nif !validHeader(hdr) { return fmt.Errorf(\"header %q must be 'Key: Value'\", hdr) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass headers as quoted \"Key: Value\" arguments","One -header flag per header; never combine multiple headers in one value","Validate env-var-derived header strings contain a colon before interpolation"],"tags":["cli","input-validation","http-headers"],"backgroundTag":"cli-flag-parse-error","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}