GoogleContainerTools/skaffold · error
unable to evaluate build args: %w
Error message
unable to evaluate build args: %w
What it means
MapToFlag converts a map of string values into CLI flag pairs (--flag key=value), first evaluating each value as an env template via EvaluateEnvTemplateMap. This error means that evaluation failed for at least one value, so flag construction is aborted. The misleading 'build args' wording is generic; it applies to any map passed to MapToFlag.
Source
Thrown at pkg/skaffold/util/env_template.go:120
}
value, err := ExpandEnvTemplate(*v, env)
if err != nil {
return nil, fmt.Errorf("unable to get value for key %q: %w", k, err)
}
evaluated[k] = &value
}
return evaluated, nil
}
// MapToFlag parses all map values and returns them as `key=value` with the given flag
// Example: --my-flag key0=value0 --my-flag key1=value1 --my-flag key2=value2
func MapToFlag(m map[string]*string, flag string) ([]string, error) {
kv, err := EvaluateEnvTemplateMap(m)
if err != nil {
return nil, fmt.Errorf("unable to evaluate build args: %w", err)
}
var keys []string
for k := range kv {
keys = append(keys, k)
}
sort.Strings(keys)
var kvFlags []string
for _, k := range keys {
v := kv[k]
if v == nil {
kvFlags = append(kvFlags, flag, k)
} else {
kvFlags = append(kvFlags, flag, fmt.Sprintf("%s=%s", k, *v))
}
}
View on GitHub (pinned to a1189de023)
Solutions
- Inspect each value in the map for balanced, valid {{.VAR}} template expressions.
- Escape or remove literal '{{'/'}}' from values that should be plain strings.
- Verify required environment variables exist before invoking, if using missingkey=error paths.
- Test the map with EvaluateEnvTemplateMap in a unit check before building flags.
Example fix
// before
m := map[string]*string{"tag": ptr("{{.VERSION")}
flags, err := util.MapToFlag(m, "--tag")
// after
m := map[string]*string{"tag": ptr("{{.VERSION}}")}
flags, err := util.MapToFlag(m, "--tag") Defensive patterns
Strategy: try-catch
Validate before calling
for k, v := range m {
if v != nil && strings.Contains(*v, "{") && !isValidEnvTemplate(*v) {
return fmt.Errorf("flag value for %q is not a valid template", k)
}
} Type guard
func canBuildFlags(m map[string]*string) bool {
_, err := util.EvaluateEnvTemplateMap(m)
return err == nil
} Try / catch
flags, err := util.MapToFlag(m, "--build-arg")
if err != nil {
if strings.Contains(err.Error(), "unable to evaluate build args") {
return fmt.Errorf("one of the map values has broken template syntax: %w", err)
}
return err
} Prevention
- Pre-validate the map with EvaluateEnvTemplateMap before building flags
- Escape literal braces in values intended as plain strings
- Keep env expansion inputs consistent across CLI and config paths
When it happens
Trigger: EvaluateEnvTemplateMap(m) returns an error: any value in the map contains malformed Go-template syntax or a value that fails to expand (missing key when missingkey=error is set upstream, or unparseable {{...}}).
Common situations: Passing CLI override maps (--default-repo, --profile, set-values style maps) where an entry contains a broken template like '{{.IMAGE' ; scripted invocations interpolating partial braces; literal braces in values.
Related errors
- unable to evaluate cli flags: %w
- unable to parse template: %q: %w
- unable to get value for key %q: %w
- bucket name is empty
- INSPECT_PROFILE_NOT_FOUND_ERR
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/ab83e5e984460140.
Report an issue: GitHub.