{"record":{"id":"b3320946030eb78d","repo":"kubernetes/kops","slug":"error-writing-cluster-json-to-stdout-v-b33209","errorCode":null,"errorMessage":"error writing cluster json to stdout: %v","messagePattern":"error writing cluster json to stdout: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/toolbox_instance-selector.go","lineNumber":335,"sourceCode":"\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\n\t\tif err := fullOutputYAML(out, ig); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing cluster yaml to stdout: %v\", err)\n\t\t}\n\t}","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/toolbox_instance-selector.go#L317-L353","documentation":"Wraps a failure of fullOutputJSON while `kops toolbox instance-selector --dry-run -o json` serializes a generated instance group to stdout. The dry-run output stream write failed, not the instance-group computation.","triggerScenarios":"fullOutputJSON returns an error during JSON encoding of the InstanceGroup or writing to the out writer (broken pipe, encoder failure).","commonSituations":"Downstream consumer of the pipe exits before consuming all JSON; stdout redirected to a full filesystem; JSON encoder choking on a field produced by an unusual spec decoration.","solutions":["If the cause is EPIPE, rerun writing to a file instead of a pipe.","Confirm disk space for the redirected output target.","Try --output yaml to check whether only the JSON path fails.","Inspect the wrapped encoder error for the offending field."],"exampleFix":"// before\nkops toolbox instance-selector --output json ... | jq '.[0]' | head\n// after\nkops toolbox instance-selector --output json ... > igs.json","handlingStrategy":"try-catch","validationCode":"if options.Output != OutputJSON {\n\treturn fmt.Errorf(\"expected --output json for this path\")\n}","typeGuard":null,"tryCatchPattern":"if err := fullOutputJSON(out, true, 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 json to stdout: %v\", err)\n}","preventionTips":["Redirect JSON output to a file instead of fragile pipes.","Check disk space for large dry-run outputs.","Cross-check with --output yaml when JSON encoding misbehaves."],"tags":["json","serialization","dry-run"],"backgroundTag":"json-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"}