GoogleContainerTools/skaffold · error

unable to parse template: %q: %w

Error message

unable to parse template: %q: %w

What it means

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.

Source

Thrown at pkg/skaffold/util/env_template.go:46

	"github.com/Masterminds/sprig"

	"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log"
)

// For testing
var (
	OSEnviron = os.Environ
	funcsMap  = template.FuncMap{
		"cmd": runCmdFunc,
	}
)

// ExpandEnvTemplate parses and executes template s with an optional environment map
func ExpandEnvTemplate(s string, envMap map[string]string) (string, error) {
	tmpl, err := ParseEnvTemplate(s)
	if err != nil {
		return "", fmt.Errorf("unable to parse template: %q: %w", s, err)
	}
	return ExecuteEnvTemplate(tmpl, envMap)
}

// ExpandEnvTemplateOrFail parses and executes template s with an optional environment map, and errors if a reference cannot be satisfied.
func ExpandEnvTemplateOrFail(s string, envMap map[string]string) (string, error) {
	tmpl, err := ParseEnvTemplate(s)
	if err != nil {
		return "", fmt.Errorf("unable to parse template: %q: %w", s, err)
	}
	tmpl = tmpl.Option("missingkey=error")
	return ExecuteEnvTemplate(tmpl, envMap)
}

// ParseEnvTemplate is a simple wrapper to parse an env template
func ParseEnvTemplate(t string) (*template.Template, error) {
	return template.New("envTemplate").Funcs(funcsMap).Funcs(sprig.FuncMap()).Parse(t)
}

View on GitHub (pinned to a1189de023)

Solutions

  1. Locate the offending string in skaffold.yaml (the %q in the message shows it) and fix the unbalanced/invalid {{...}} expression.
  2. Escape literal braces or remove them if templating was not intended.
  3. Validate template syntax with a Go text/template playground or 'skaffold diagnose'.
  4. Use the correct env-template syntax: {{.ENV_VAR}} or {{.FOO}} — not {{ENV_VAR}} without a dot.
  5. For JSON/velocity-style syntax from other tools, convert to Go template syntax.

Example fix

// before: invalid template — missing closing brace
image: gcr.io/proj/app:{{.TAG
// after
image: gcr.io/proj/app:{{.TAG}}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-validate template syntax
if _, err := template.New("env").Funcs(envTemplateFuncs).Parse(s); err != nil {
    return fmt.Errorf("invalid env template %q: %w", s, err)
}

Type guard

func isValidEnvTemplate(s string) bool {
    _, err := template.New("check").Parse(s)
    return err == nil
}

Try / catch

expanded, err := util.ExpandEnvTemplate(cfgValue, envMap)
if err != nil {
    var perr error // wrapped parse error
    if strings.Contains(err.Error(), "unable to parse template") {
        return fmt.Errorf("malformed template in config value %q: %w", cfgValue, err)
    }
    return err
}

Prevention

When it happens

Trigger: 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 '{{}'.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/5c98b21299489f25. Report an issue: GitHub.