{"record":{"id":"7f5c391b1bb5b33f","repo":"GoogleContainerTools/skaffold","slug":"executing-template-w","errorCode":null,"errorMessage":"executing template: %w","messagePattern":"executing template: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/skaffold/app/cmd/build.go","lineNumber":78,"sourceCode":"\t\t}).\n\t\tWithHouseKeepingMessages().\n\t\tNoArgs(doBuild)\n}\n\nfunc doBuild(ctx context.Context, out io.Writer) error {\n\tbuildOut := out\n\tif quietFlag {\n\t\tbuildOut = io.Discard\n\t}\n\n\treturn withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error {\n\t\tbRes, err := r.Build(ctx, buildOut, targetArtifacts(opts, configs))\n\n\t\tif quietFlag || buildOutputFlag != \"\" {\n\t\t\tcmdOut := flags.BuildOutput{Builds: bRes}\n\t\t\tvar buildOutput bytes.Buffer\n\t\t\tif err := buildFormatFlag.Template().Execute(&buildOutput, cmdOut); err != nil {\n\t\t\t\treturn fmt.Errorf(\"executing template: %w\", err)\n\t\t\t}\n\n\t\t\tif quietFlag {\n\t\t\t\tif _, err := out.Write(buildOutput.Bytes()); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"writing build output: %w\", err)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif buildOutputFlag != \"\" {\n\t\t\t\tif err := os.WriteFile(buildOutputFlag, buildOutput.Bytes(), 0644); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"writing build output to file: %w\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn err\n\t})\n}","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/cmd/skaffold/app/cmd/build.go#L60-L96","documentation":"In the `skaffold build` command (cmd/skaffold/app/cmd/build.go:78), when --quiet or --build-output is used, the build results are rendered through the build format template (buildFormatFlag.Template().Execute). If template execution fails, this error wraps the underlying template error.","triggerScenarios":"Running `skaffold build --quiet` or `skaffold build --build-output <file>` with a --build-format template that fails to execute against the flags.BuildOutput{Builds: bRes} data (invalid template syntax, referencing a non-existent field, bad custom template).","commonSituations":"User-supplied --build-format Go template with a typo or unsupported field; incompatible template written for an older skaffold output schema; malformed JSON/GOTEMPLATE value passed to --build-format.","solutions":["Validate the custom --build-format template syntax (Go template) and field names against the BuildOutput struct","Remove the custom --build-format flag to use the default template and confirm the error disappears","Check the bRes structure for the version of skaffold in use and update template fields accordingly","Ensure the build itself succeeded (r.Build's err is handled later); template runs even on results only when quiet/output is set"],"exampleFix":"// before\n// skaffold build --quiet --build-format '{{.Builds.Image}}'\n// after (Builds is a slice; range over it)\n// skaffold build --quiet --build-format '{{range .Builds}}{{.ImageName}}{{end}}'","handlingStrategy":"validation","validationCode":"// Pre-validate a custom build format template by rendering a dummy BuildOutput\ntmpl, err := template.New(\"out\").Parse(customFormat)\nif err != nil {\n    return fmt.Errorf(\"invalid --build-format template: %w\", err)\n}\nif err := tmpl.Execute(io.Discard, flags.BuildOutput{}); err != nil {\n    return fmt.Errorf(\"template incompatible with BuildOutput: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := sh.Run(\"skaffold\", \"build\", \"--quiet\", \"--build-format\", format); err != nil {\n    if strings.Contains(err.Error(), \"executing template\") {\n        log.Fatalf(\"bad --build-format %q; check Go template syntax and field names\", format)\n    }\n    return err\n}","preventionTips":["Test custom --build-format templates against a sample build result before CI","Use the default template unless structured output is truly needed","Keep templates in sync with the skaffold version's output schema","Prefer --build-output JSON (stable schema) over free-form templates"],"tags":["cli","build","template","go-templates"],"backgroundTag":"template-execution-failed","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"}