{"record":{"id":"49ee5361bcbb210c","repo":"hashicorp/nomad","slug":"no-formatting-option-given","errorCode":null,"errorMessage":"no formatting option given","messagePattern":"no formatting option given","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/data_format.go","lineNumber":87,"sourceCode":"\t}\n\n\terr = t.Execute(&out, data)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn out.String(), nil\n}\n\nfunc Format(json bool, template string, data any) (string, error) {\n\tvar format string\n\tif json && len(template) > 0 {\n\t\treturn \"\", fmt.Errorf(\"Both json and template formatting are not allowed\")\n\t} else if json {\n\t\tformat = \"json\"\n\t} else if len(template) > 0 {\n\t\tformat = \"template\"\n\t} else {\n\t\treturn \"\", fmt.Errorf(\"no formatting option given\")\n\t}\n\n\tf, err := DataFormat(format, template)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tout, err := f.TransformData(data)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Error formatting the data: %w\", err)\n\t}\n\n\treturn out, nil\n}\n\nfunc makeFuncMap() template.FuncMap {\n\tfm := template.FuncMap{}\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/data_format.go#L69-L105","documentation":"Format (command/data_format.go) builds a data formatter for Nomad CLI output but requires exactly one formatting option: -json, a -template, or a default format. If none of the json/template flags was supplied and no default was assigned, it refuses to guess and returns \"no formatting option given\".","triggerScenarios":"Calling command.Format(data, false, \"\") — i.e. json=false and template empty — with no fallback format set before the if/else chain in Format.","commonSituations":"A caller (Run, multiregionPlan, checkUpgrade, csiFormatPlugin[s], ouputClaims) forgets to read the json/template flags from the CLI meta, or wires up a new command passing zero-value booleans/strings for both options.","solutions":["Pass -json or -template on the CLI command invocation","In the calling command, default json/template from Meta flags (e.g. read f := getMeta(); ensure one of json/template is set) before calling Format","If embedding Format in new code, provide a default format (e.g. format = \"json\" or table) when both options are absent"],"exampleFix":"// before\nout, err := c.Format(data, false, \"\")\n// after\njsonFlag := meta.flagJson\ntmplFlag := meta.flagTemplate\nif !jsonFlag && tmplFlag == \"\" {\n    jsonFlag = true // or pick a default format\n}\nout, err := c.Format(data, jsonFlag, tmplFlag)","handlingStrategy":"validation","validationCode":"if !json && template == \"\" {\n    return fmt.Errorf(\"either -json or -template must be provided\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always read json/template flags from shared Meta before calling Format","Establish a default output format for new commands","Add a unit test asserting Format errors clearly when both options are empty"],"tags":["cli","formatting","argument-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"}