GoogleContainerTools/skaffold · error

setting template flag: %w

Error message

setting template flag: %w

What it means

TemplateFlag.Set parses the value of the `--default-repo`/output template flags with parseTemplate. If the string is not a valid Go text/template (bad syntax, unclosed actions), the parse error is wrapped as `setting template flag: ...` at flag-parse time, before skaffold does any work.

Source

Thrown at cmd/skaffold/app/flags/template.go:51

func (t *TemplateFlag) String() string {
	return t.rawTemplate
}

func (t *TemplateFlag) Usage() string {
	defaultUsage := "Format output with go-template."
	if t.context != nil {
		goType := reflect.TypeOf(t.context)
		url := fmt.Sprintf("https://godoc.org/%s#%s", goType.PkgPath(), goType.Name())
		defaultUsage += fmt.Sprintf(" For full struct documentation, see %s", url)
	}
	return defaultUsage
}

func (t *TemplateFlag) Set(value string) error {
	tmpl, err := parseTemplate(value)
	if err != nil {
		return fmt.Errorf("setting template flag: %w", err)
	}
	t.rawTemplate = value
	t.template = tmpl
	return nil
}

func (t *TemplateFlag) Type() string {
	return fmt.Sprintf("%T", t)
}

func (t *TemplateFlag) Template() *template.Template {
	return t.template
}

func NewTemplateFlag(value string, context interface{}) *TemplateFlag {
	return &TemplateFlag{
		template:    template.Must(parseTemplate(value)),
		rawTemplate: value,

View on GitHub (pinned to a1189de023)

Solutions

  1. Fix the template syntax; ensure every `{{` has a matching `}}` (e.g. `{{.IMAGE_NAME}}`).
  2. Single-quote the flag value in shells to prevent brace/variable expansion.
  3. Test the template in isolation with a small Go template or by echoing the intended output.

Example fix

// before
skaffold run --default-repo '{{.REPO'
// after
skaffold run --default-repo 'gcr.io/my-project'
Defensive patterns

Strategy: validation

Validate before calling

if strings.Count(tpl, "{{") != strings.Count(tpl, "}}") {
    return fmt.Errorf("unbalanced template braces in %q", tpl)
}

Try / catch

if err := cmd.Run(); err != nil {
    if strings.Contains(err.Error(), "setting template flag") {
        // fix template syntax and re-run
    }
}

Prevention

When it happens

Trigger: Passing a template flag value with invalid Go template syntax, e.g. `--default-repo '{{.REPO'` (unclosed `{{`), or illegal template constructs; verified by TestTemplateSet.

Common situations: Shell interpolation eating the closing braces; copying templates with unsupported template functions; quoting mistakes so the value contains stray braces.

Related errors


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