{"record":{"id":"318548082217cc3a","repo":"hashicorp/nomad","slug":"unsupported-format-is-specified","errorCode":null,"errorMessage":"Unsupported format is specified.","messagePattern":"Unsupported format is specified\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/data_format.go","lineNumber":39,"sourceCode":"\n// DataFormatter is a transformer of the data.\ntype DataFormatter interface {\n\t// TransformData should return transformed string data.\n\tTransformData(any) (string, error)\n}\n\n// DataFormat returns the data formatter specified format.\nfunc DataFormat(format, tmpl string) (DataFormatter, error) {\n\tswitch format {\n\tcase \"json\":\n\t\tif len(tmpl) > 0 {\n\t\t\treturn nil, fmt.Errorf(\"json format does not support template option.\")\n\t\t}\n\t\treturn &JSONFormat{}, nil\n\tcase \"template\":\n\t\treturn &TemplateFormat{tmpl}, nil\n\t}\n\treturn nil, fmt.Errorf(\"Unsupported format is specified.\")\n}\n\ntype JSONFormat struct{}\n\n// TransformData returns JSON format string data.\nfunc (p *JSONFormat) TransformData(data any) (string, error) {\n\tvar buf bytes.Buffer\n\terr := codec.NewEncoder(&buf, jsonHandlePretty).Encode(data)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn buf.String(), nil\n}\n\ntype TemplateFormat struct {\n\ttmpl string\n}","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/data_format.go#L21-L57","documentation":"DataFormat returns this error when the format argument matches neither \"json\" nor \"template\" (the fallthrough at the end of the switch). The library only supports these two output formatters, so any other format string is unsupported.","triggerScenarios":"Calling command.DataFormat(format, tmpl) with format values like \"\", \"text\", \"pretty\", or a typo such as \"jso\" / \"templete\".","commonSituations":"Typo in the -format flag value; empty format because a flag was never set; copy-pasted format names from other tools (e.g. \"yaml\"); upstream code passing an uninitialized format variable.","solutions":["Pass exactly \"json\" or \"template\" as the format value.","Check the -format flag value for typos and case (values are lowercase, exact match).","Ensure the format flag has a default set in your command wiring so it is never empty.","If you need another output type, implement your own DataFormatter instead of extending DataFormat."],"exampleFix":"// before\nf, err := command.DataFormat(\"jso\", \"\")\n// after\nf, err := command.DataFormat(\"json\", \"\")","handlingStrategy":"validation","validationCode":"var validFormats = map[string]bool{\"json\": true, \"template\": true}\nif !validFormats[format] {\n    return fmt.Errorf(\"format must be json or template, got %q\", format)\n}","typeGuard":"null","tryCatchPattern":"f, err := command.DataFormat(format, tmpl)\nif err != nil {\n    if strings.Contains(err.Error(), \"Unsupported format\") {\n        f, err = command.DataFormat(\"json\", \"\") // safe fallback\n    }\n}","preventionTips":["Use a constant/enum for format values instead of free-form strings.","Set a default format (json) in flag definitions so it is never empty.","Validate flag values at parse time with allowed-value lists.","Keep format strings lowercase and exact — no case normalization is performed."],"tags":["cli","format","validation"],"backgroundTag":"unsupported-format-specified","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"}