{"record":{"id":"f5e826d2cc5f5019","repo":"kubernetes/kops","slug":"error-writing-cluster-json-to-stdout-v","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/create_cluster.go","lineNumber":816,"sourceCode":"\t\t\t\tSpec: api.SSHCredentialSpec{\n\t\t\t\t\tPublicKey: strings.TrimSpace(string(key)),\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\n\t\tfor _, o := range addons {\n\t\t\tobj = append(obj, o.ToUnstructured())\n\t\t}\n\n\t\tswitch c.Output {\n\t\tcase OutputYaml:\n\t\t\tif err := fullOutputYAML(out, obj...); 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, obj...); 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\", c.Output)\n\t\t}\n\t}\n\n\t// Note we perform as much validation as we can, before writing a bad config\n\terr = registry.CreateClusterConfig(ctx, clientset, cluster, instanceGroups, addons)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error writing updated configuration: %v\", err)\n\t}\n\n\tif len(c.SSHPublicKeys) == 0 {\n\t\tautoloadSSHPublicKeys := true\n\t\tswitch c.CloudProvider {\n\t\tcase \"gce\", \"aws\":\n\t\t\tautoloadSSHPublicKeys = false","sourceCodeStart":798,"sourceCodeEnd":834,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create_cluster.go#L798-L834","documentation":"Same flow as the YAML variant but for --output json: fullOutputJSON fails to marshal the objects or write them to stdout. RunCreateCluster wraps and returns the error, aborting the dry-run output path.","triggerScenarios":"`kops create cluster --dry-run --output json` where fullOutputJSON returns an error (JSON marshal failure or writer failure).","commonSituations":"Stdout redirected to an unwritable target in shell pipelines; an object set containing something not JSON-serializable (rare; usually a kops bug).","solutions":["Ensure the redirect target is writable and the pipe stays open.","Re-run without redirection to isolate the cause.","Use --output yaml as a fallback to still inspect the dry-run spec.","File an issue with the wrapped error if it is a marshal failure on a default spec."],"exampleFix":"// before\nkops create cluster ... --dry-run --output json > /dev/full\n// after\nkops create cluster ... --dry-run --output json > cluster.json","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := runCreateCluster(...); err != nil {\n\tif strings.Contains(err.Error(), \"error writing cluster json\") {\n\t\t// fall back to --output yaml, which uses a different serializer\n\t}\n\treturn err\n}","preventionTips":["Redirect dry-run JSON output to a writable file.","Use --output yaml as a fallback when JSON serialization fails.","Verify the redirect target has free disk space.","Report marshal failures on default specs as kops bugs."],"tags":["cli","dry-run","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"}