{"record":{"id":"ea967ac53774cb2b","repo":"kubernetes/kops","slug":"error-writing-yaml-to-stdout-v","errorCode":null,"errorMessage":"error writing yaml to stdout: %v","messagePattern":"error writing yaml to stdout: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/get_all.go","lineNumber":129,"sourceCode":"\t\t\taddonObjects = append(addonObjects, addon.ToUnstructured())\n\t\t}\n\t}\n\n\tvar allObjects []runtime.Object\n\tif options.Output != OutputTable {\n\t\tallObjects = append(allObjects, cluster)\n\t\tfor _, group := range instancegroups {\n\t\t\tallObjects = append(allObjects, group)\n\t\t}\n\t\tfor _, additionalObject := range addonObjects {\n\t\t\tallObjects = append(allObjects, additionalObject)\n\t\t}\n\t}\n\n\tswitch options.Output {\n\tcase OutputYaml:\n\t\tif err := fullOutputYAML(out, allObjects...); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing yaml to stdout: %v\", err)\n\t\t}\n\n\t\treturn nil\n\n\tcase OutputJSON:\n\t\tif err := fullOutputJSON(out, false, allObjects...); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing json to stdout: %v\", err)\n\t\t}\n\t\treturn nil\n\n\tcase OutputTable:\n\t\tfmt.Fprintf(out, \"Cluster\\n\")\n\t\terr = clusterOutputTable([]*api.Cluster{cluster}, out)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tfmt.Fprintf(out, \"\\nInstance Groups\\n\")\n\t\terr = igOutputTable(cluster, instancegroups, out)","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get_all.go#L111-L147","documentation":"Wraps any error from fullOutputYAML, which serializes all fetched objects (cluster, instance groups, addons) to YAML and writes them to stdout. The marshal step itself may fail (codec issues like error 340) or the write to the output writer may fail. The wrapper contextualizes the failure as a YAML output problem.","triggerScenarios":"`kops get all <cluster> -o yaml` where any of the collected objects fails YAML/JSON conversion (unregistered kind, versioning failure) or writing to stdout fails (closed pipe, full disk).","commonSituations":"Piping output to `head`/a closed pipe causing EPIPE; an addon or instance group object the codecs cannot version; kops version skew with objects stored in the state store.","solutions":["Read the wrapped inner error to distinguish marshal failure from write failure","Avoid closing the pipe early (e.g. don't use `| head` or redirect to a writable file)","Check for unregistered/unsupported object kinds and align kops version with cluster state","Retry writing to a file instead of stdout to rule out terminal/pipe issues"],"exampleFix":"// before\nkops get all mycluster.example.com -o yaml | head -5\n// after\nkops get all mycluster.example.com -o yaml > cluster.yaml","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := fullOutputYAML(out, allObjects...); err != nil {\n    if errors.Is(err, syscall.EPIPE) {\n        return nil // consumer closed the pipe; treat as benign\n    }\n    return fmt.Errorf(\"error writing yaml to stdout: %v\", err)\n}","preventionTips":["Avoid piping kops output to commands that exit early (head)","Write to a file for large outputs","Keep kops version aligned with the cluster's stored API version","Check disk space before large -o yaml dumps"],"tags":["yaml","output","serialization","cli"],"backgroundTag":"yaml-serialize-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}