kubernetes/kops · error
error writing json to stdout: %v
Error message
error writing json to stdout: %v
What it means
Wraps any error from fullOutputJSON, which serializes the fetched objects to JSON and writes them to stdout. This mirrors error 342 for the JSON path; the underlying failure is either a marshaling/codec error or a write error on the output stream.
Source
Thrown at cmd/kops/get_all.go:136
for _, group := range instancegroups {
allObjects = append(allObjects, group)
}
for _, additionalObject := range addonObjects {
allObjects = append(allObjects, additionalObject)
}
}
switch options.Output {
case OutputYaml:
if err := fullOutputYAML(out, allObjects...); err != nil {
return fmt.Errorf("error writing yaml to stdout: %v", err)
}
return nil
case OutputJSON:
if err := fullOutputJSON(out, false, allObjects...); err != nil {
return fmt.Errorf("error writing json to stdout: %v", err)
}
return nil
case OutputTable:
fmt.Fprintf(out, "Cluster\n")
err = clusterOutputTable([]*api.Cluster{cluster}, out)
if err != nil {
return err
}
fmt.Fprintf(out, "\nInstance Groups\n")
err = igOutputTable(cluster, instancegroups, out)
if err != nil {
return err
}
if len(addonObjects) != 0 {
fmt.Fprintf(out, "\nAddon Objects\n")
err = addonsOutputTable(cluster, addonObjects, out)
if err != nil {View on GitHub (pinned to 4c8573c808)
Solutions
- Inspect the wrapped inner error for the marshal vs write distinction
- Align kops CLI version with the cluster state-store version
- Use `--name`/full cluster name and rerun; verify state store readability
- Write to a file instead of a pipe to avoid write failures
Example fix
// before
j, err := fullOutputJSON(out, false, allObjects...)
if err != nil { return fmt.Errorf("error writing json to stdout: %v", err) }
// after
if err := fullOutputJSON(buf, false, allObjects...); err != nil { return err }
_, err = out.Write(buf.Bytes()) Defensive patterns
Strategy: try-catch
Try / catch
if err := fullOutputJSON(out, false, allObjects...); err != nil {
if errors.Is(err, syscall.EPIPE) {
return nil // downstream consumer closed stdout
}
return fmt.Errorf("error writing json to stdout: %v", err)
} Prevention
- Consume full output instead of truncating with head
- Parse with jq only after the command exits 0
- Align kops CLI version with state-store version
- Redirect to file when output is large
When it happens
Trigger: `kops get all <cluster> -o json` where object serialization via the codecs fails (unregistered kind, version conversion) or the write to stdout fails.
Common situations: State-store objects from a newer kops version with fields the current codecs reject; piping to a closed pipe; scripting `kops get all -o json` and consuming output while the writer errors.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- error writing cluster json to stdout: %v
- error marshaling json: %v
- error writing yaml to stdout: %v
- unable to marshal JSON: %v
- unable to marshal JSON: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/df2de8ccba97f5a9.
Report an issue: GitHub.