{"record":{"id":"f3aec0fd7140abe5","repo":"kubernetes/kops","slug":"error-writing-cluster-yaml-to-stdout-v-f3aec0","errorCode":null,"errorMessage":"error writing cluster yaml to stdout: %v","messagePattern":"error writing cluster yaml to stdout: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/toolbox_instance-selector.go","lineNumber":331,"sourceCode":"\t\tig, err = cloudup.PopulateInstanceGroupSpec(cluster, ig, cloud, channel)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tnewInstanceGroups = append(newInstanceGroups, ig)\n\n\t\tif igCount != 1 {\n\t\t\tdoubledRatio := (*mutatedFilters.VCpusToMemoryRatio) * 2\n\t\t\tmutatedFilters.VCpusToMemoryRatio = &doubledRatio\n\t\t}\n\t}\n\n\tif options.DryRun {\n\t\tfor _, ig := range newInstanceGroups {\n\t\t\tswitch options.Output {\n\t\t\tcase OutputYaml:\n\t\t\t\tif err := fullOutputYAML(out, ig); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"error writing cluster yaml to stdout: %v\", err)\n\t\t\t\t}\n\t\t\tcase OutputJSON:\n\t\t\t\tif err := fullOutputJSON(out, true, ig); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"error writing cluster json to stdout: %v\", err)\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn fmt.Errorf(\"unsupported output type %q\", options.Output)\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t}\n\n\tfor _, ig := range newInstanceGroups {\n\t\t_, err = clientset.InstanceGroupsFor(cluster).Create(ctx, ig, metav1.CreateOptions{})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error storing InstanceGroup: %v\", err)\n\t\t}\n","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/toolbox_instance-selector.go#L313-L349","documentation":"In --dry-run mode with YAML output, fullOutputYAML(out, ig) failed to serialize/write the generated InstanceGroup to stdout. The error is the YAML marshaling or writer failure, wrapped with the cluster-yaml message.","triggerScenarios":"fullOutputYAML returns an error during yaml.Marshal of the InstanceGroup or when writing to the out writer (e.g. broken pipe, serialization of an unsupported field).","commonSituations":"Piping output into a command that exits early (`| head`) causing EPIPE; an InstanceGroup field that cannot be marshaled due to a kOps version mismatch of schema types.","solutions":["Check the wrapped cause: if it is EPIPE, the downstream consumer closed stdout — rerun without the pipe or with `cat`.","Rerun with --output json to see if JSON serialization succeeds, isolating the YAML issue.","Ensure stdout is a writable, open stream (no redirect to a full disk).","Upgrade/downgrade kOps if the serialized spec fields mismatch your expected schema."],"exampleFix":"// before\nkops toolbox instance-selector ... | head -5\n// after\nkops toolbox instance-selector ... > instance-groups.yaml","handlingStrategy":"try-catch","validationCode":"if options.Output != OutputYaml && options.Output != OutputJSON {\n\treturn fmt.Errorf(\"unsupported output %q; use yaml|json\", options.Output)\n}","typeGuard":null,"tryCatchPattern":"if err := fullOutputYAML(out, ig); err != nil {\n\tif errors.Is(err, syscall.EPIPE) {\n\t\tlog.Println(\"stdout closed by consumer; output discarded\")\n\t\treturn nil\n\t}\n\treturn fmt.Errorf(\"error writing cluster yaml to stdout: %v\", err)\n}","preventionTips":["Avoid piping kOps output into commands that may exit early (e.g. head).","Write dry-run output to a file for deterministic capture.","Validate the --output flag before running."],"tags":["yaml","serialization","dry-run"],"backgroundTag":"yaml-serialization-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"}