{"record":{"id":"17329d4b94411431","repo":"kubernetes/kops","slug":"snippet-cannot-have-the-same-name-as-the-template","errorCode":null,"errorMessage":"snippet cannot have the same name as the template: %s","messagePattern":"snippet cannot have the same name as the template: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/templater/templater.go","lineNumber":58,"sourceCode":"\t\tchannel: channel,\n\t}\n}\n\n// Render is responsible for actually rendering the template\nfunc (r *Templater) Render(content string, context map[string]interface{}, snippets map[string]string, failOnMissing bool) (rendered string, err error) {\n\t// @step: create the template\n\ttm := template.New(templateName)\n\tif _, err = tm.Funcs(r.templateFuncsMap(tm)).Parse(content); err != nil {\n\t\treturn\n\t}\n\tif failOnMissing {\n\t\ttm.Option(\"missingkey=error\")\n\t}\n\n\t// @step: add the snippits into the mix\n\tfor filename, snippet := range snippets {\n\t\tif filename == templateName {\n\t\t\treturn \"\", fmt.Errorf(\"snippet cannot have the same name as the template: %s\", filename)\n\t\t}\n\t\tif _, err = tm.New(filename).Parse(snippet); err != nil {\n\t\t\treturn rendered, fmt.Errorf(\"unable to parse snippet: %s, error: %s\", filename, err)\n\t\t}\n\t}\n\n\t// @step: render the actual template\n\twriter := new(bytes.Buffer)\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"failed to parse template, error: %s\", r)\n\t\t}\n\t}()\n\tif err = tm.ExecuteTemplate(writer, templateName, context); err != nil {\n\t\treturn\n\t}\n\n\treturn writer.String(), nil","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/util/templater/templater.go#L40-L76","documentation":"templater.Render builds a Go text/template from the main template plus optional named snippets. A snippet registered under the exact same name as the template itself would overwrite the template in the template set, so Render rejects it up front with this error naming the conflicting filename.","triggerScenarios":"Calling Render with a snippets map containing a key equal to the templateName argument — e.g. a snippet file named the same as the base template (both \"cluster.yaml\") in the snippets directory.","commonSituations":"Dropping a snippet file into the snippets dir with the same basename as the main template, or programmatically building a snippets map where one key collides with the template name.","solutions":["Rename the snippet so it differs from the template name shown in the error","Check the snippets directory for a file whose basename matches the template and move/delete it","If generating snippets programmatically, assert keys != templateName before calling Render"],"exampleFix":"// before\nsnippets := map[string]string{\"nodeup\": snippet} // collides with templateName \"nodeup\"\nrendered, err := t.Render(snippets, values, \"nodeup\", \"\")\n// after\nsnippets := map[string]string{\"nodeup-config\": snippet}\nrendered, err := t.Render(snippets, values, \"nodeup\", \"\")","handlingStrategy":"validation","validationCode":"// Reject colliding snippet keys before Render\nfor name := range snippets {\n\tif name == templateName {\n\t\treturn fmt.Errorf(\"snippet %q collides with template name\", name)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name snippet files distinctly from template basenames","Lint snippets directories for basename collisions in CI","When building snippets maps programmatically, assert unique, non-colliding keys"],"tags":["templating","naming-conflict"],"backgroundTag":"template-name-collision","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"}