{"record":{"id":"101e934e2fb9c3bc","repo":"kubernetes/kops","slug":"unable-to-render-template-s-error-s","errorCode":null,"errorMessage":"unable to render template: %s, error: %s","messagePattern":"unable to render template: (.+?), error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/toolbox_template.go","lineNumber":184,"sourceCode":"\t}\n\n\tchannel, err := kopsapi.LoadChannel(f.VFSContext(), options.channel)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error loading channel %q: %v\", options.channel, err)\n\t}\n\n\t// @step: render each of the templates, splitting on the documents\n\tr := templater.NewTemplater(channel)\n\tvar documents []string\n\tfor _, x := range templates {\n\t\tcontent, err := os.ReadFile(x)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to read template: %s, error: %s\", x, err)\n\t\t}\n\n\t\trendered, err := r.Render(string(content), context, snippets, options.failOnMissing)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to render template: %s, error: %s\", x, err)\n\t\t}\n\t\t// @check if the content is zero ignore it\n\t\tif len(rendered) <= 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\tif !options.formatYAML {\n\t\t\tdocuments = append(documents, strings.Split(rendered, \"---\\n\")...)\n\t\t\tcontinue\n\t\t}\n\n\t\tfor _, x := range strings.Split(rendered, \"---\\n\") {\n\t\t\tvar data map[string]interface{}\n\t\t\tif err := yaml.Unmarshal([]byte(x), &data); err != nil {\n\t\t\t\treturn fmt.Errorf(\"unable to unmarshall content from template: %s, error: %s\", x, err)\n\t\t\t}\n\t\t\tif len(data) <= 0 {\n\t\t\t\tcontinue","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/toolbox_template.go#L166-L202","documentation":"Returned by RunToolBoxTemplate when templater.Render fails to render a template's content with the given context values and snippets. The templater performs Go text/template-like substitution; errors arise from template syntax problems or, when --fail-on-missing is set, from context keys referenced in the template that are absent from the values file. The template path and renderer error are wrapped in the message.","triggerScenarios":"Rendering a template containing invalid template syntax (unclosed {{ }}, bad functions/pipelines) or — with failOnMissing enabled — referencing {{ .someKey }} where \"someKey\" is not defined in the --values/context map.","commonSituations":"Missing key in the --values YAML that the template expects (with strict mode on); typos in template variables; pasting snippets with stray {{ }} sequences; incompatible template syntax after upgrading kOps or hand-editing templates; multiline expressions the parser rejects.","solutions":["Inspect the wrapped error for the exact template construct that failed; fix the syntax at the reported location","If it's a missing key: add the key to your --values file, or remove --fail-on-missing if a default/empty render is acceptable","Verify template delimiters/functions are correct: match them against a known-good template in the kOps repo examples","Re-render with a minimal values file to isolate which variable breaks the render","Check snippets included into the template for stray {{ }} markup"],"exampleFix":"// before (template)\nclusterName: {{ .clusterNam }}\n\n// after\nclusterName: {{ .clusterName }}","handlingStrategy":"try-catch","validationCode":"for key := range extractTemplateKeys(templateText) {\n    if _, ok := context[key]; !ok && failOnMissing {\n        return fmt.Errorf(\"context key %q missing but required by template\", key)\n    }\n}","typeGuard":null,"tryCatchPattern":"rendered, err := r.Render(content, context, snippets, failOnMissing)\nif err != nil {\n    if failOnMissing && strings.Contains(err.Error(), \"missing\") {\n        return fmt.Errorf(\"add missing keys to --values or drop --fail-on-missing: %w\", err)\n    }\n    return fmt.Errorf(\"fix template syntax: %w\", err)\n}","preventionTips":["Keep a values file that defines every key referenced in templates","Run renders with --fail-on-missing in CI to catch missing keys early","Lint templates with a Go text/template parser before committing","Quote substituted values to avoid breaking downstream YAML"],"tags":["kops","templates","rendering","validation"],"backgroundTag":"template-render-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}