GoogleContainerTools/skaffold · error
setting template flag: %w
Error message
setting template flag: %w
What it means
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.
Source
Thrown at cmd/skaffold/app/flags/build_output.go:69
buf []byte
err error
)
if value == "-" {
buf, err = io.ReadAll(os.Stdin)
} else {
if _, err := os.Stat(value); os.IsNotExist(err) {
return err
}
buf, err = os.ReadFile(value)
}
if err != nil {
return err
}
buildOutput, err := ParseBuildOutput(buf)
if err != nil {
return fmt.Errorf("setting template flag: %w", err)
}
t.filename = value
t.buildOutput = *buildOutput
return nil
}
// Type Implements Type() method for pflag interface
func (t *BuildOutputFileFlag) Type() string {
return fmt.Sprintf("%T", t)
}
// BuildArtifacts returns the Build Artifacts in the BuildOutputFileFlag
func (t *BuildOutputFileFlag) BuildArtifacts() []graph.Artifact {
return t.buildOutput.Builds
}
// NewBuildOutputFileFlag returns a new BuildOutputFile without any validationView on GitHub (pinned to a1189de023)
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.
Example fix
// before skaffold deploy --build-output old-partial.json // after skaffold build --file-output artifacts.json && skaffold deploy --build-output artifacts.json
Defensive patterns
Strategy: validation
Validate before calling
if _, err := os.Stat(buildOutputFile); err != nil {
return err
}
if err := json.NewDecoder(f).Decode(&struct{}{}); err != nil {
return fmt.Errorf("%s is not valid JSON", buildOutputFile)
} Try / catch
if err := cmd.Run(); err != nil {
if strings.Contains(err.Error(), "setting template flag") {
// check the --build-output file for valid JSON
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.
Related errors
- %s: %w
- `apply` requires at least one manifest argument
- `exec` requires exactly one action to execute
- `config-dependencies add` requires exactly one file path arg
- `jobManifestPaths modify` requires exactly one manifest file
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/3422cd5a4c273378.
Report an issue: GitHub.