{"record":{"id":"3422cd5a4c273378","repo":"GoogleContainerTools/skaffold","slug":"setting-template-flag-w","errorCode":null,"errorMessage":"setting template flag: %w","messagePattern":"setting template flag: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/skaffold/app/flags/build_output.go","lineNumber":69,"sourceCode":"\t\tbuf []byte\n\t\terr error\n\t)\n\n\tif value == \"-\" {\n\t\tbuf, err = io.ReadAll(os.Stdin)\n\t} else {\n\t\tif _, err := os.Stat(value); os.IsNotExist(err) {\n\t\t\treturn err\n\t\t}\n\t\tbuf, err = os.ReadFile(value)\n\t}\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tbuildOutput, err := ParseBuildOutput(buf)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"setting template flag: %w\", err)\n\t}\n\n\tt.filename = value\n\tt.buildOutput = *buildOutput\n\treturn nil\n}\n\n// Type Implements Type() method for pflag interface\nfunc (t *BuildOutputFileFlag) Type() string {\n\treturn fmt.Sprintf(\"%T\", t)\n}\n\n// BuildArtifacts returns the Build Artifacts in the BuildOutputFileFlag\nfunc (t *BuildOutputFileFlag) BuildArtifacts() []graph.Artifact {\n\treturn t.buildOutput.Builds\n}\n\n// NewBuildOutputFileFlag returns a new BuildOutputFile without any validation","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/cmd/skaffold/app/flags/build_output.go#L51-L87","documentation":"The `--build-output` / template flag's Set() parses the flag value (a filename or JSON/template) via ParseBuildOutput. If parsing fails, the underlying parse error is wrapped as `setting template flag: ...`. It surfaces during flag parsing before any build runs.","triggerScenarios":"Passing `--build-output` a file whose content is not valid build-output JSON, a nonexistent/unreadable file, or malformed template syntax on the command line or in scripts.","commonSituations":"Pointing --build-output at a file produced by a different tool; truncated output file from a previous failed build; shell quoting issues mangling JSON inline values.","solutions":["Validate the file is valid JSON matching the build-artifacts schema (jq . < file).","Regenerate the file with `skaffold build --file-output` rather than reusing old/manual output.","Check the file path is correct and readable by the skaffold process."],"exampleFix":"// before\nskaffold deploy --build-output old-partial.json\n// after\nskaffold build --file-output artifacts.json && skaffold deploy --build-output artifacts.json","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(buildOutputFile); err != nil {\n    return err\n}\nif err := json.NewDecoder(f).Decode(&struct{}{}); err != nil {\n    return fmt.Errorf(\"%s is not valid JSON\", buildOutputFile)\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(); err != nil {\n    if strings.Contains(err.Error(), \"setting template flag\") {\n        // check the --build-output file for valid JSON\n    }\n}","preventionTips":["Always produce the file with `skaffold build --file-output`, never manually.","Run `jq . file` as a smoke test in CI before passing it as a flag.","Quote flag values in shell to avoid JSON mangling."],"tags":["cli","flags","json-parsing","skaffold"],"backgroundTag":"invalid-flag-value","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"}