{"record":{"id":"db31a3f549f9c1db","repo":"GoogleContainerTools/skaffold","slug":"executing-template-w-db31a3","errorCode":null,"errorMessage":"executing template: %w","messagePattern":"executing template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/tag/custom_template.go","lineNumber":118,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"evaluating custom template component: %w\", err)\n\t\t}\n\t\tcustomMap[k] = tag\n\t}\n\treturn customMap, nil\n}\n\n// ParseCustomTemplate is a simple wrapper to parse an custom template.\nfunc ParseCustomTemplate(t string) (*template.Template, error) {\n\treturn template.New(\"customTemplate\").Parse(t)\n}\n\n// ExecuteCustomTemplate executes a customTemplate against a custom map.\nfunc ExecuteCustomTemplate(customTemplate *template.Template, customMap map[string]string) (string, error) {\n\tvar buf bytes.Buffer\n\tlog.Entry(context.TODO()).Debugf(\"Executing custom template %v with custom map %v\", customTemplate, customMap)\n\tif err := customTemplate.Execute(&buf, customMap); err != nil {\n\t\treturn \"\", fmt.Errorf(\"executing template: %w\", err)\n\t}\n\treturn buf.String(), nil\n}\n","sourceCodeStart":100,"sourceCodeEnd":122,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/tag/custom_template.go#L100-L122","documentation":"The parsed custom template failed when executed against the resolved custom map. `ExecuteCustomTemplate` runs `customTemplate.Execute(&buf, customMap)`; execution-time errors (as opposed to parse-time) are wrapped here. Typically caused by referencing a map key that was never provided by any component.","triggerScenarios":"`GenerateTag` (and anonymous callers) call `ExecuteCustomTemplate` after `EvaluateComponents`; the template references a field (e.g. `{{.GIT}}`) whose value is missing from customMap or an option/template function misbehaves during rendering.","commonSituations":"Component tagger returned empty/error but evaluation was partially bypassed; template uses a key differing from the map keys set in EvaluateComponents; nil/missing map entry rendering.","solutions":["Ensure every field in the template has a matching entry in customMap (same key casing)","Check the wrapped cause for the exact Execute error (missing key vs function error)","Align template fields with the components configured in skaffold.yaml","Add debugging: log the customMap keys before execution"],"exampleFix":"// before: template key not in map\nExecuteCustomTemplate(tmpl, map[string]string{\"SHA\": \"abc\"}) // tmpl uses {{.GIT}}\n// after: supply all fields\nExecuteCustomTemplate(tmpl, map[string]string{\"SHA\": \"abc\", \"GIT\": \"main-9d1f2c3\"})","handlingStrategy":"type-guard","validationCode":"// verify every template field exists in the map before executing\nfor _, f := range tag.GetTemplateFields(tmplString) {\n    if _, ok := customMap[f]; !ok {\n        return fmt.Errorf(\"template field %q missing from resolved components\", f)\n    }\n}","typeGuard":"func canExecute(customTemplate *template.Template, customMap map[string]string) bool {\n    return customTemplate != nil && customMap != nil && len(customMap) > 0\n}","tryCatchPattern":"result, err := tag.ExecuteCustomTemplate(tmpl, customMap)\nif err != nil {\n    if strings.Contains(err.Error(), \"executing template\") {\n        return fmt.Errorf(\"template references missing component key: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep template keys identical to component names in the map","Log customMap keys in debug before executing","Unit-test ExecuteCustomTemplate with the real skaffold.yaml template","Avoid building the map dynamically with inconsistent casing"],"tags":["templating","tagging","configuration"],"backgroundTag":"template-execute-error","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"}