{"record":{"id":"0f372e7a972e3a7b","repo":"GoogleContainerTools/skaffold","slug":"error-executing-template-w","errorCode":null,"errorMessage":"error executing template: %w","messagePattern":"error executing template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/generator/generate.go","lineNumber":42,"sourceCode":"\ntype Container struct {\n\tName  string\n\tImage string\n\tPort  int\n}\n\n// Generate generates kubernetes resources for the given image, and returns the generated manifest string\nfunc Generate(name string, port int) ([]byte, *Container, error) {\n\tc := Container{name, name, port}\n\n\tt, err := template.New(\"deployment\").Parse(yamlTemplate)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"error parsing pod template: %w\", err)\n\t}\n\n\tvar buf bytes.Buffer\n\tif err = t.Execute(&buf, c); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"error executing template: %w\", err)\n\t}\n\n\treturn buf.Bytes(), &c, nil\n}\n","sourceCodeStart":24,"sourceCodeEnd":47,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/generator/generate.go#L24-L47","documentation":"Generate parses the deployment template and then executes it into a bytes.Buffer to render the manifest for the given container name and port. This error is returned when template.Execute fails while rendering the template against the Container value — typically a data-reference problem (missing field, method error) or an I/O error writing to the buffer.","triggerScenarios":"Calling Generate(name, port) where the parsed yamlTemplate references fields/functions not available on the Container struct (which only has Name and Port), or a writer error on the internal bytes.Buffer.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped error — text/template reports the exact failing action/field","Ensure every {{.Field}} in yamlTemplate exists on the Container struct (only Name and Port are set)","If the template was customized, validate field names and any custom funcs registered with the template's FuncMap","Rebuild Skaffold from pristine source if you did not modify the template"],"exampleFix":"// before: field missing on struct\ntemplate: `name: {{.Name}}\\nimage: {{.Image}}`\n// after: use existing fields on Container{name, name, port}\ntemplate: `name: {{.Name}}\\nimage: {{.Name}}\\nport: {{.Port}}`","handlingStrategy":"validation","validationCode":"// Ensure the data struct carries every field the template references\nfields := []string{\"Name\", \"Port\"}\nfor _, f := range fields {\n    if _, found := reflect.TypeOf(c).FieldByName(f); !found {\n        return fmt.Errorf(\"template field %s missing on Container struct\", f)\n    }\n}","typeGuard":null,"tryCatchPattern":"buf := &bytes.Buffer{}\nif err := t.Execute(buf, c); err != nil {\n    if strings.Contains(err.Error(), \"error executing template\") {\n        log.Errorf(\"template/data mismatch: %v\", err)\n    }\n    return nil, err\n}","preventionTips":["Keep template field references in sync with the Container struct; add a render unit test","Avoid adding pipeline funcs to the embedded template without registering them","Render the default manifest in CI to catch regressions"],"tags":["go-templates","kubernetes","manifest-generation"],"backgroundTag":"template-execute-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}