{"record":{"id":"8acc5403bfe7bb11","repo":"kubernetes/kops","slug":"unable-to-parse-snippet-s-error-s","errorCode":null,"errorMessage":"unable to parse snippet: %s, error: %s","messagePattern":"unable to parse snippet: (.+?), error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/templater/templater.go","lineNumber":61,"sourceCode":"\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\n}\n\n// indentContent is responsible for indenting the string content","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/util/templater/templater.go#L43-L79","documentation":"During Render, each snippet is parsed into the shared template set via tm.New(filename).Parse(snippet). If a snippet contains invalid Go template syntax (unclosed actions, bad functions, malformed pipelines), parsing fails and Render returns this error naming the snippet and the underlying parse error.","triggerScenarios":"Calling Render with any snippet whose body is not valid text/template syntax — e.g. `{{ if .Foo }}` without `{{ end }}`, unknown functions, wrong pipe usage.","commonSituations":"Hand-edited model snippet files with typos, snippets copied from templates using functions unavailable in this context, or dynamically generated snippet strings with interpolation bugs.","solutions":["Fix the template syntax in the named snippet; read the parse error's line/column hint and validate with `gotemplate` linters or a small Go test using text/template","Check for unclosed {{ if }}/{{ range }} blocks and misspelled template functions","Compare the snippet against a known-good sibling snippet in the models directory"],"exampleFix":"// before\n\"{{ range .Nodes }}\n  {{ .Name }}\n\" // missing {{ end }}\n// after\n\"{{ range .Nodes }}\n  {{ .Name }}\n{{ end }}\"","handlingStrategy":"validation","validationCode":"// Parse snippet standalone before Render\nprobe := template.New(templateName)\nfor name, body := range snippets {\n\tif _, err := probe.New(name).Parse(body); err != nil {\n\t\treturn fmt.Errorf(\"invalid snippet %s: %w\", name, err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"rendered, err := t.Render(snippets, values, templateName, \"\")\nif err != nil {\n\tif strings.Contains(err.Error(), \"unable to parse snippet\") {\n\t\treturn fmt.Errorf(\"fix snippet syntax: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Lint model snippet files with a Go template parser in CI","Check balanced {{ if }}/{{ range }}/{{ end }} blocks after edits","Only use template functions registered in the target template set","Diff edited snippets against known-good siblings before committing"],"tags":["templating","parse-error","gotemplate"],"backgroundTag":"template-syntax-error","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}