{"record":{"id":"5c98b21299489f25","repo":"GoogleContainerTools/skaffold","slug":"unable-to-parse-template-q-w","errorCode":null,"errorMessage":"unable to parse template: %q: %w","messagePattern":"unable to parse template: %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/util/env_template.go","lineNumber":46,"sourceCode":"\n\t\"github.com/Masterminds/sprig\"\n\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log\"\n)\n\n// For testing\nvar (\n\tOSEnviron = os.Environ\n\tfuncsMap  = template.FuncMap{\n\t\t\"cmd\": runCmdFunc,\n\t}\n)\n\n// ExpandEnvTemplate parses and executes template s with an optional environment map\nfunc ExpandEnvTemplate(s string, envMap map[string]string) (string, error) {\n\ttmpl, err := ParseEnvTemplate(s)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"unable to parse template: %q: %w\", s, err)\n\t}\n\treturn ExecuteEnvTemplate(tmpl, envMap)\n}\n\n// ExpandEnvTemplateOrFail parses and executes template s with an optional environment map, and errors if a reference cannot be satisfied.\nfunc ExpandEnvTemplateOrFail(s string, envMap map[string]string) (string, error) {\n\ttmpl, err := ParseEnvTemplate(s)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"unable to parse template: %q: %w\", s, err)\n\t}\n\ttmpl = tmpl.Option(\"missingkey=error\")\n\treturn ExecuteEnvTemplate(tmpl, envMap)\n}\n\n// ParseEnvTemplate is a simple wrapper to parse an env template\nfunc ParseEnvTemplate(t string) (*template.Template, error) {\n\treturn template.New(\"envTemplate\").Funcs(funcsMap).Funcs(sprig.FuncMap()).Parse(t)\n}","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/util/env_template.go#L28-L64","documentation":"ExpandEnvTemplate parses string s as a Go text/template for environment expansion, then executes it against envMap. This error means the template syntax itself is invalid — parsing failed before any values were substituted. The offending string and parse error are wrapped.","triggerScenarios":"ParseEnvTemplate(s) fails on malformed template syntax in config fields: unbalanced {{ }} (e.g. '{{NAME'), invalid pipeline functions, bad characters like '{{.{{', or stray unmatched braces in values like IMAGE_TAG '{{}'.","commonSituations":"skaffold.yaml values (image names, helm set values, build args) containing literal '{{' or '}}' meant as plain text; typos in template expressions; shell-style ${} mixed with Go {{}} syntax by mistake.","solutions":["Locate the offending string in skaffold.yaml (the %q in the message shows it) and fix the unbalanced/invalid {{...}} expression.","Escape literal braces or remove them if templating was not intended.","Validate template syntax with a Go text/template playground or 'skaffold diagnose'.","Use the correct env-template syntax: {{.ENV_VAR}} or {{.FOO}} — not {{ENV_VAR}} without a dot.","For JSON/velocity-style syntax from other tools, convert to Go template syntax."],"exampleFix":"// before: invalid template — missing closing brace\nimage: gcr.io/proj/app:{{.TAG\n// after\nimage: gcr.io/proj/app:{{.TAG}}","handlingStrategy":"try-catch","validationCode":"// pre-validate template syntax\nif _, err := template.New(\"env\").Funcs(envTemplateFuncs).Parse(s); err != nil {\n    return fmt.Errorf(\"invalid env template %q: %w\", s, err)\n}","typeGuard":"func isValidEnvTemplate(s string) bool {\n    _, err := template.New(\"check\").Parse(s)\n    return err == nil\n}","tryCatchPattern":"expanded, err := util.ExpandEnvTemplate(cfgValue, envMap)\nif err != nil {\n    var perr error // wrapped parse error\n    if strings.Contains(err.Error(), \"unable to parse template\") {\n        return fmt.Errorf(\"malformed template in config value %q: %w\", cfgValue, err)\n    }\n    return err\n}","preventionTips":["Use balanced {{.VAR}} Go-template syntax; always close braces","Run 'skaffold diagnose' before deploy to catch template syntax errors","Quote template values in YAML to avoid parser surprises","Avoid literal '{{' in values; escape or restructure them"],"tags":["templating","go-templates","config"],"backgroundTag":"template-parse-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"}