{"record":{"id":"ab83e5e984460140","repo":"GoogleContainerTools/skaffold","slug":"unable-to-evaluate-build-args-w-ab83e5","errorCode":null,"errorMessage":"unable to evaluate build args: %w","messagePattern":"unable to evaluate build args: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/util/env_template.go","lineNumber":120,"sourceCode":"\t\t}\n\n\t\tvalue, err := ExpandEnvTemplate(*v, env)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to get value for key %q: %w\", k, err)\n\t\t}\n\n\t\tevaluated[k] = &value\n\t}\n\n\treturn evaluated, nil\n}\n\n// MapToFlag parses all map values and returns them as `key=value` with the given flag\n// Example: --my-flag key0=value0 --my-flag key1=value1  --my-flag key2=value2\nfunc MapToFlag(m map[string]*string, flag string) ([]string, error) {\n\tkv, err := EvaluateEnvTemplateMap(m)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to evaluate build args: %w\", err)\n\t}\n\n\tvar keys []string\n\tfor k := range kv {\n\t\tkeys = append(keys, k)\n\t}\n\tsort.Strings(keys)\n\n\tvar kvFlags []string\n\tfor _, k := range keys {\n\t\tv := kv[k]\n\t\tif v == nil {\n\t\t\tkvFlags = append(kvFlags, flag, k)\n\t\t} else {\n\t\t\tkvFlags = append(kvFlags, flag, fmt.Sprintf(\"%s=%s\", k, *v))\n\t\t}\n\t}\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/util/env_template.go#L102-L138","documentation":"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.","triggerScenarios":"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 {{...}}).","commonSituations":"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.","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."],"exampleFix":"// before\nm := map[string]*string{\"tag\": ptr(\"{{.VERSION\")}\nflags, err := util.MapToFlag(m, \"--tag\")\n// after\nm := map[string]*string{\"tag\": ptr(\"{{.VERSION}}\")}\nflags, err := util.MapToFlag(m, \"--tag\")","handlingStrategy":"try-catch","validationCode":"for k, v := range m {\n    if v != nil && strings.Contains(*v, \"{\") && !isValidEnvTemplate(*v) {\n        return fmt.Errorf(\"flag value for %q is not a valid template\", k)\n    }\n}","typeGuard":"func canBuildFlags(m map[string]*string) bool {\n    _, err := util.EvaluateEnvTemplateMap(m)\n    return err == nil\n}","tryCatchPattern":"flags, err := util.MapToFlag(m, \"--build-arg\")\nif err != nil {\n    if strings.Contains(err.Error(), \"unable to evaluate build args\") {\n        return fmt.Errorf(\"one of the map values has broken template syntax: %w\", err)\n    }\n    return err\n}","preventionTips":["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"],"tags":["templating","cli-flags","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"}