{"record":{"id":"fd91daa1dfd96f56","repo":"kubernetes/kops","slug":"unable-to-marshal-yaml-v-fd91da","errorCode":null,"errorMessage":"unable to marshal YAML: %v","messagePattern":"unable to marshal YAML: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/get_instances.go","lineNumber":162,"sourceCode":"\n\tcloudGroups, err := cloud.GetCloudGroups(cluster, instanceGroups, false, nodeList.Items)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfor _, cg := range cloudGroups {\n\t\tcloudInstances = append(cloudInstances, cg.Ready...)\n\t\tcloudInstances = append(cloudInstances, cg.NeedUpdate...)\n\t\tcg.AdjustNeedUpdate()\n\t}\n\n\tswitch options.Output {\n\tcase OutputTable:\n\t\treturn instanceOutputTable(cloudInstances, out)\n\tcase OutputYaml:\n\t\ty, err := yaml.Marshal(asRenderable(cloudInstances))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to marshal YAML: %v\", err)\n\t\t}\n\t\tif _, err := out.Write(y); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing to output: %v\", err)\n\t\t}\n\t\treturn nil\n\tcase OutputJSON:\n\t\tj, err := json.Marshal(asRenderable(cloudInstances))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to marshal JSON: %v\", err)\n\t\t}\n\t\tif _, err := out.Write(j); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing to output: %v\", err)\n\t\t}\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported output format: %q\", options.Output)\n\t}\n}","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get_instances.go#L144-L180","documentation":"When `kops get instances --output yaml` runs, the cloud instance list is converted with asRenderable and serialized with sigs.k8s.io/yaml.Marshal. If marshaling fails, the command returns \"unable to marshal YAML: %v\". sigs.k8s.io/yaml converts to JSON first, so this almost always means the data cannot be JSON-encoded (e.g. unsupported types such as channels, funcs, or NaN), which is extremely rare for the plain-string renderable struct used here.","triggerScenarios":"`kops get instances -o yaml` where yaml.Marshal(asRenderable(cloudInstances)) returns an error at get_instances.go:160-162 — e.g. a renderableCloudInstance field carrying a value not representable in JSON/YAML (NaN float, invalid UTF-8 from cloud provider metadata).","commonSituations":"Cloud provider returns instance metadata with invalid UTF-8 bytes that end up in a string field; a corrupted custom build injecting non-serializable values; tampered vendored types.","solutions":["Check which instance/field fails: print instances with `kops get instances` (table) to isolate the offending instance","Inspect the instance metadata in your cloud console for malformed characters (NaN, invalid UTF-8) and fix at the source","Use `--output json` to see whether JSON marshaling succeeds, narrowing the problem to the YAML path","Upgrade kops; if reproducible with clean metadata, file a bug with the wrapped error text"],"exampleFix":"// before\ny, err := yaml.Marshal(asRenderable(cloudInstances))\n// after: inspect what fails\nj, jsonErr := json.Marshal(asRenderable(cloudInstances))\nif jsonErr != nil {\n    klog.Warningf(\"JSON marshal also failed: %v\", jsonErr) // pinpoints non-serializable field\n}\ny, err := yaml.Marshal(asRenderable(cloudInstances))","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func marshalable(instances []*cloudinstances.CloudInstance) bool {\n    _, err := json.Marshal(asRenderable(instances))\n    return err == nil\n}","tryCatchPattern":"y, err := yaml.Marshal(asRenderable(cloudInstances))\nif err != nil {\n    return fmt.Errorf(\"unable to marshal YAML: %w\", err)\n}","preventionTips":["Prefer stock kops releases; avoid forks adding non-JSON-encodable fields","Keep instance metadata (tags, names) within valid UTF-8","Test `--output yaml` in CI on a representative cluster before scripting on it","Remember sigs.k8s.io/yaml goes through JSON: any JSON-invalid value will fail"],"tags":["yaml","serialization","cli-output"],"backgroundTag":"yaml-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"}