{"record":{"id":"95df70045b8f6174","repo":"hashicorp/nomad","slug":"format-flag-required","errorCode":null,"errorMessage":"format flag required","messagePattern":"format flag required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/var_put.go","lineNumber":431,"sourceCode":"\t\tout.Path = path\n\t\tout.Namespace = c.Meta.namespace\n\t\tout.Items = make(map[string]string)\n\t\treturn out, nil\n\t}\n\n\tswitch c.inFmt {\n\tcase \"json\":\n\t\terr = json.Unmarshal(c.contents, out)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error unmarshaling json: %w\", err)\n\t\t}\n\tcase \"hcl\":\n\t\tout, err = parseVariableSpec(c.contents, c.verbose)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error parsing hcl: %w\", err)\n\t\t}\n\tcase \"\":\n\t\treturn nil, errors.New(\"format flag required\")\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unknown format flag value\")\n\t}\n\n\t// It is possible a specification file was used which did not declare any\n\t// items. Therefore, default the entry to avoid panics and ensure this type\n\t// of use is valid.\n\tif out.Items == nil {\n\t\tout.Items = make(map[string]string)\n\t}\n\n\t// Handle cases where values are provided by CLI flags that modify the\n\t// the created variable. Typical of a \"copy\" operation, it is a convenience\n\t// to reset the Create and Modify metadata to zero.\n\tvar resetIndex bool\n\n\t// Step on the namespace in the object if one is provided by flag\n\tif c.Meta.namespace != \"\" && c.Meta.namespace != out.Namespace {","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/var_put.go#L413-L449","documentation":"VarPutCommand.makeVariable requires the -format flag (hcl or json) to know how to parse the variable contents. When no format was supplied (empty string), it returns this error before parsing anything.","triggerScenarios":"Running `vault kv put` (var put) with data/contents but without -in/-format, so c.format (inFmt) is \"\" when makeVariable switches on it.","commonSituations":"Piping a file via stdin without specifying -in=hcl or -in=json; upgrading from a workflow where format defaulted implicitly; scripts missing the flag after refactor.","solutions":["Add -in=hcl or -in=json (matching your input contents) to the command","If using a spec file, ensure the format flag is still provided","Check the command help for the exact flag name in your version"],"exampleFix":"// before\nvault kv put secret/foo @spec.hcl\n// after\nvault kv put -in=hcl secret/foo @spec.hcl","handlingStrategy":"validation","validationCode":"if inFmt == \"\" {\n\treturn errors.New(\"-in (hcl|json) is required when supplying contents to kv put\")\n}\nif inFmt != \"hcl\" && inFmt != \"json\" {\n\treturn fmt.Errorf(\"invalid -in %q\", inFmt)\n}","typeGuard":null,"tryCatchPattern":"_, err := cmd.makeVariable()\nif err != nil {\n\tif err.Error() == \"format flag required\" {\n\t\t// re-invoke with -in=hcl or -in=json\n\t}\n\treturn err\n}","preventionTips":["Always pass -in=hcl or -in=json when using file/stdin contents","Include the format flag in scripted put invocations","Validate arguments with a wrapper before executing"],"tags":["go","cli","flags","validation"],"backgroundTag":"missing-required-flag","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"}