{"record":{"id":"ac02746f294a4875","repo":"kubernetes/kops","slug":"snippet-s-issue-s","errorCode":null,"errorMessage":"snippet: %s, issue: %s","messagePattern":"snippet: (.+?), issue: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/templater/templater.go","lineNumber":106,"sourceCode":"\t\t}\n\t\t// @step: write the line to the buffer\n\t\tline := fmt.Sprintf(\"%\"+fmt.Sprintf(\"%d\", spacer)+\"s%s\", \"\", x)\n\t\tb.WriteString(line)\n\n\t\t// @check if we need a newline\n\t\tif i < length {\n\t\t\tb.WriteString(\"\\n\")\n\t\t}\n\t}\n\n\treturn b.String()\n}\n\n// includeSnippet is responsible for including a snippet\nfunc includeSnippet(tm *template.Template, name string, context map[string]interface{}) (string, error) {\n\tb := bytes.NewBufferString(\"\")\n\tif err := tm.ExecuteTemplate(b, name, context); err != nil {\n\t\treturn \"\", fmt.Errorf(\"snippet: %s, issue: %s\", name, err)\n\t}\n\n\treturn b.String(), nil\n}\n","sourceCodeStart":88,"sourceCodeEnd":111,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/util/templater/templater.go#L88-L111","documentation":"includeSnippet executes a named template snippet against a context and wraps any ExecuteTemplate error with the snippet name for diagnosability. Unlike a syntax error, this failure happens during execution of the snippet — missing data keys, bad pipelines, or function errors. The snippet name in the message tells you exactly which nested include failed.","triggerScenarios":"tm.ExecuteTemplate(b, name, context) returns an error while rendering the snippet named `name` — e.g. the snippet references a key absent from context, or a pipeline type mismatch (executing a field of an int as a map).","commonSituations":"A snippet template expects a context key (e.g. a region, zone, or config value) that the caller did not set; snippet files edited/customized with incompatible expressions; version mismatch between snippet templates and the code supplying context.","solutions":["Read `snippet: <name>` in the message and open that snippet; the wrapped `issue` names the failing expression or missing key","Add the missing context key or fix the snippet's expression to match the actual context type","If you customized bundled snippets, diff them against upstream for the matching kOps version","Test the snippet standalone with tmpl.ExecuteTemplate on a minimal context reproducing the data"],"exampleFix":"// before: snippet references context[\"KubernetesVersion\"] but caller never set it\ncontext := map[string]interface{}{\"Region\": \"us-east-1\"}\nincludeSnippet(tm, \"networking\", context) // snippet: networking, issue: map has no entry for key \"KubernetesVersion\"\n// after\ncontext := map[string]interface{}{\"Region\": \"us-east-1\", \"KubernetesVersion\": \"1.28.0\"}\nincludeSnippet(tm, \"networking\", context)","handlingStrategy":"validation","validationCode":"keys := []string{\"Region\", \"KubernetesVersion\"}\nfor _, k := range keys {\n    if _, ok := context[k]; !ok {\n        return fmt.Errorf(\"context missing %q required by snippet %s\", k, name)\n    }\n}","typeGuard":null,"tryCatchPattern":"s, err := includeSnippet(tm, name, context)\nif err != nil {\n    return fmt.Errorf(\"rendering snippet %s: %w\", name, err) // name already embedded in the wrapped error\n}","preventionTips":["Keep snippet context keys documented and pass all of them from callers","Diff customized snippets against upstream after kOps upgrades","Test each snippet standalone with a minimal context"],"tags":["go","templates","snippets","kops"],"backgroundTag":"template-render-panic","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"}