GoogleContainerTools/skaffold · error

executing template: %w

Error message

executing template: %w

What it means

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.

Source

Thrown at pkg/skaffold/tag/custom_template.go:118

		if err != nil {
			return nil, fmt.Errorf("evaluating custom template component: %w", err)
		}
		customMap[k] = tag
	}
	return customMap, nil
}

// ParseCustomTemplate is a simple wrapper to parse an custom template.
func ParseCustomTemplate(t string) (*template.Template, error) {
	return template.New("customTemplate").Parse(t)
}

// ExecuteCustomTemplate executes a customTemplate against a custom map.
func ExecuteCustomTemplate(customTemplate *template.Template, customMap map[string]string) (string, error) {
	var buf bytes.Buffer
	log.Entry(context.TODO()).Debugf("Executing custom template %v with custom map %v", customTemplate, customMap)
	if err := customTemplate.Execute(&buf, customMap); err != nil {
		return "", fmt.Errorf("executing template: %w", err)
	}
	return buf.String(), nil
}

View on GitHub (pinned to a1189de023)

Solutions

  1. Ensure every field in the template has a matching entry in customMap (same key casing)
  2. Check the wrapped cause for the exact Execute error (missing key vs function error)
  3. Align template fields with the components configured in skaffold.yaml
  4. Add debugging: log the customMap keys before execution

Example fix

// before: template key not in map
ExecuteCustomTemplate(tmpl, map[string]string{"SHA": "abc"}) // tmpl uses {{.GIT}}
// after: supply all fields
ExecuteCustomTemplate(tmpl, map[string]string{"SHA": "abc", "GIT": "main-9d1f2c3"})
Defensive patterns

Strategy: type-guard

Validate before calling

// verify every template field exists in the map before executing
for _, f := range tag.GetTemplateFields(tmplString) {
    if _, ok := customMap[f]; !ok {
        return fmt.Errorf("template field %q missing from resolved components", f)
    }
}

Type guard

func canExecute(customTemplate *template.Template, customMap map[string]string) bool {
    return customTemplate != nil && customMap != nil && len(customMap) > 0
}

Try / catch

result, err := tag.ExecuteCustomTemplate(tmpl, customMap)
if err != nil {
    if strings.Contains(err.Error(), "executing template") {
        return fmt.Errorf("template references missing component key: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: `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.

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

Related errors


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