{"record":{"id":"dff91835c71853ff","repo":"hashicorp/nomad","slug":"a-template-must-be-supplied-using-template-when-dff918","errorCode":null,"errorMessage":"A template must be supplied using '-template' when using go-template formatting","messagePattern":"A template must be supplied using '-template' when using go-template formatting","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/var_put.go","lineNumber":608,"sourceCode":"func (c *VarPutCommand) validateInputFlag() error {\n\tswitch c.inFmt {\n\tcase \"hcl\", \"json\":\n\t\treturn nil\n\tdefault:\n\t\treturn errors.New(errInvalidInFormat)\n\t}\n}\n\nfunc (c *VarPutCommand) validateOutputFlag() error {\n\tif c.outFmt != \"go-template\" && c.tmpl != \"\" {\n\t\treturn errors.New(errUnexpectedTemplate)\n\t}\n\tswitch c.outFmt {\n\tcase \"none\", \"json\", \"hcl\", \"table\":\n\t\treturn nil\n\tcase \"go-template\":\n\t\tif c.tmpl == \"\" {\n\t\t\treturn errors.New(errMissingTemplate)\n\t\t}\n\t\treturn nil\n\tdefault:\n\t\treturn errors.New(errInvalidOutFormat)\n\t}\n}\n\nfunc warnInvalidIdentifier(in string) error {\n\tinvalid := invalidIdentifier.FindAllString(in, -1)\n\tif len(invalid) == 0 {\n\t\treturn nil\n\t}\n\n\t// Use %s instead of %q to avoid escaping characters.\n\treturn fmt.Errorf(\n\t\t`\"%s\" contains characters %s that require the 'index' function for direct access in templates`,\n\t\tin,\n\t\tformatInvalidVarKeyChars(invalid),","sourceCodeStart":590,"sourceCodeEnd":626,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/var_put.go#L590-L626","documentation":"The Nomad CLI 'var put' (and similar) command validates the -out format flag via validateOutputFlag. When 'go-template' is chosen as the output format, a corresponding -template string must also be supplied; otherwise the command aborts with this error. It exists to prevent rendering with an empty template, which would produce useless empty output.","triggerScenarios":"Running a command with `-out=go-template` (or `outFmt=\"go-template\"`) while `c.tmpl` is empty, i.e. the `-template` flag was not provided or was set to an empty string.","commonSituations":"Users switching output format to go-template and forgetting the -template flag; scripts setting -out conditionally but always omitting -template; copy-pasted commands where -template was accidentally dropped.","solutions":["Add a non-empty -template flag, e.g. `-out go-template -template '{{.Key}}'`","If you don't need templating, use one of the built-in formats: -out table, json, hcl, or none","Fix the calling script to pass -template whenever -out is go-template"],"exampleFix":"// before\nnomad var put -out go-template app/secret key=value\n// after\nnomad var put -out go-template -template '{{ range .Items }}{{ .Key }}={{ .Value }}{{ end }}' app/secret key=value","handlingStrategy":"validation","validationCode":"out, tmpl := flags.GetString(\"out\"), flags.GetString(\"template\")\nif out == \"go-template\" && strings.TrimSpace(tmpl) == \"\" {\n    return fmt.Errorf(\"-template is required when -out=go-template\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair -out go-template with -template in command wrappers","Build CLI helper functions that validate flag combinations before exec","Default to -out table/json unless templating is genuinely needed"],"tags":["cli","nomad","validation","output-format"],"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"}