{"record":{"id":"504fae52697ea29b","repo":"kubernetes/kops","slug":"error-marshaling-json-v-504fae","errorCode":null,"errorMessage":"error marshaling json: %v","messagePattern":"error marshaling json: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/toolbox_dump.go","lineNumber":312,"sourceCode":"\t}\n\n\tif cloudResources != nil {\n\t\tswitch options.Output {\n\t\tcase OutputYaml:\n\t\t\tb, err := kops.ToRawYaml(cloudResources)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error marshaling yaml: %v\", err)\n\t\t\t}\n\t\t\t_, err = out.Write(b)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error writing to stdout: %v\", err)\n\t\t\t}\n\t\t\treturn nil\n\n\t\tcase OutputJSON:\n\t\t\tb, err := json.MarshalIndent(cloudResources, \"\", \"  \")\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error marshaling json: %v\", err)\n\t\t\t}\n\t\t\t_, err = out.Write(b)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error writing to stdout: %v\", err)\n\t\t\t}\n\t\t\treturn nil\n\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unsupported output format: %q\", options.Output)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":294,"sourceCodeEnd":326,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/toolbox_dump.go#L294-L326","documentation":"When `kops toolbox dump` is run with -o json, cloudResources are serialized with json.MarshalIndent. This error means the in-memory dump structure failed JSON marshaling — e.g. a value containing an unsupported type (chan, func) or an encoding failure. The command aborts with no output.","triggerScenarios":"Running `kops toolbox dump -o json` when the collected cloudResources contain values json.MarshalIndent cannot encode.","commonSituations":"kops internal type regressions; unusual cloud resources producing non-encodable data; running a dev/alpha build of kops.","solutions":["Retry with -o yaml to isolate whether only the JSON encoder fails","Update kops to the latest release","Report the failing cluster/provider to kops maintainers if reproducible"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// No caller-side validation; ensure kops version is current and the dump targets a supported cluster.","typeGuard":null,"tryCatchPattern":"b, err := json.MarshalIndent(cloudResources, \"\", \"  \")\nif err != nil {\n\treturn fmt.Errorf(\"error marshaling json: %v\", err)\n}\n// treat as unrecoverable for JSON output; retry with -o yaml if JSON fails at runtime","preventionTips":["Use released (non-dev) kops binaries","Prefer yaml output if json marshaling has failed before","Capture the full error and cluster details for a bug report"],"tags":["cli","serialization","json","dump"],"backgroundTag":"json-marshal-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"}