{"record":{"id":"869a7d6bb3adc57f","repo":"kubernetes/kops","slug":"error-writing-cluster-json-to-stdout-v-869a7d","errorCode":null,"errorMessage":"error writing cluster json to stdout: %v","messagePattern":"error writing cluster json to stdout: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/create_instancegroup.go","lineNumber":248,"sourceCode":"\tif options.DryRun {\n\n\t\tif options.Output == \"\" {\n\t\t\treturn fmt.Errorf(\"must set output flag; yaml or json\")\n\t\t}\n\n\t\t// Cluster name is not populated, and we need it\n\t\tig.ObjectMeta.Labels = make(map[string]string)\n\t\tig.ObjectMeta.Labels[kopsapi.LabelClusterName] = cluster.ObjectMeta.Name\n\n\t\tswitch options.Output {\n\t\tcase OutputYaml:\n\t\t\tif err := fullOutputYAML(out, ig); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error writing cluster yaml to stdout: %v\", err)\n\t\t\t}\n\t\t\treturn nil\n\t\tcase OutputJSON:\n\t\t\tif err := fullOutputJSON(out, true, ig); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error writing cluster json to stdout: %v\", err)\n\t\t\t}\n\t\t\treturn nil\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unsupported output type %q\", options.Output)\n\t\t}\n\t}\n\n\tif options.Edit {\n\t\tedit := editor.NewDefaultEditor(commandutils.EditorEnvs)\n\n\t\traw, err := kopscodecs.ToVersionedYaml(ig)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\text := \"yaml\"\n\n\t\t// launch the editor\n\t\tedited, file, err := edit.LaunchTempFile(fmt.Sprintf(\"%s-edit-\", filepath.Base(os.Args[0])), ext, bytes.NewReader(raw))","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create_instancegroup.go#L230-L266","documentation":"RunCreateInstanceGroup prints the newly created InstanceGroup to stdout after creation. When the configured output format is JSON, it calls fullOutputJSON to serialize the InstanceGroup; if that serialization or write fails (e.g. encoding failure or broken stdout writer), kOps wraps the underlying error with this message so the user knows the cluster object was created but could not be displayed.","triggerScenarios":"Running `kops create instancegroup --name <ig> -o json` where fullOutputJSON returns a non-nil error, most commonly an encoding/marshaling failure of the InstanceGroup object or an error writing to the output writer (out).","commonSituations":"Piping stdout to a closed pipe or full disk; a codec failure caused by an unexpected field or nil field in the InstanceGroup built from flags; running in a scripted pipeline where the consumer exits early (SIGPIPE-related write failures).","solutions":["Check the wrapped underlying error (%v) to identify whether it is an encoding or writer failure","Re-run without piping (direct to terminal) to rule out broken-pipe/stdout issues","Retry with -o yaml to see if YAML output works, isolating the JSON encoding path","Verify free disk space and writable stdout; fix any stdout redirection/pipe problems","If encoding persists, inspect the InstanceGroup fields for unusual values and file an upstream kOps issue"],"exampleFix":"// before\nkops create instancegroup --name nodes -o json | consumer-exits-early\n// after\nkops create instancegroup --name nodes -o json > ig.json 2> ig.err || cat ig.err","handlingStrategy":"try-catch","validationCode":"case \"$OUTPUT\" in yaml|json) ;; *) echo \"unsupported output: $OUTPUT\" >&2; exit 1;; esac","typeGuard":"func isSupportedOutput(o string) bool { return o == \"yaml\" || o == \"json\" }","tryCatchPattern":"if err := RunCreateInstanceGroup(ctx, f, out, options); err != nil {\n\tif strings.Contains(err.Error(), \"error writing cluster json to stdout\") {\n\t\t// fall back to yaml output or log and continue; creation already succeeded\n\t}\n}","preventionTips":["Only pass -o yaml or -o json to kops create instancegroup","Avoid piping stdout to short-lived consumers; redirect to a file instead","Check disk space and stdout writability in automation","Treat this as post-creation: the InstanceGroup exists even if printing failed"],"tags":["cli","json","output"],"backgroundTag":"stdout-write-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"}