{"record":{"id":"d64ee704c07819de","repo":"kubernetes/kops","slug":"unable-to-marshal-yaml-v-d64ee7","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_keypairs.go","lineNumber":241,"sourceCode":"\t\t\treturn \"\"\n\t\t})\n\t\tt.AddColumn(\"HASPRIVATE\", func(i *keypairItem) string {\n\t\t\tif i.HasPrivateKey {\n\t\t\t\treturn \"*\"\n\t\t\t}\n\t\t\treturn \"\"\n\t\t})\n\t\tcolumnNames := []string{\"NAME\", \"ID\", \"ISSUED\", \"EXPIRES\"}\n\t\tif options.Distrusted {\n\t\t\tcolumnNames = append(columnNames, \"DISTRUSTED\")\n\t\t}\n\t\tcolumnNames = append(columnNames, \"PRIMARY\", \"HASPRIVATE\")\n\t\treturn t.Render(items, out, columnNames...)\n\n\tcase OutputYaml:\n\t\ty, err := yaml.Marshal(items)\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\tcase OutputJSON:\n\t\tj, err := json.Marshal(items)\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\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown output format: %q\", options.Output)\n\t}\n\n\treturn nil","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get_keypairs.go#L223-L259","documentation":"In RunGetKeypairs, the OutputYaml branch marshals the []*keypairItem slice with yaml.Marshal. If marshaling fails (unsupported type in the items, marshaler misconfiguration), the error is wrapped as \"unable to marshal YAML: %v\". This is a serialization failure before any bytes reach the output writer.","triggerScenarios":"`kops get keypairs -o yaml` where yaml.Marshal(items) errors — practically rare for keypairItem slices, but possible via unserializable field types or a yaml library incompatibility after a dependency upgrade.","commonSituations":"Custom builds where keypairItem gained a field of an unsupported type; vendoring/go.mod drift between kubernetes-sigs/yaml versions; binary built against mismatched library versions.","solutions":["Read the wrapped %v cause to identify the offending field/type.","Fall back to `-o json` to still get machine-readable output while isolating the YAML issue.","Rebuild kops with a clean module cache (`make kops` after `go clean -modcache`) to rule out dependency drift.","If reproducible on upstream kops, file an issue with the wrapped error text."],"exampleFix":"// before\nkops get keypairs -o yaml   # unable to marshal YAML\n// after (workaround)\nkops get keypairs -o json","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := runKops(\"get\", \"keypairs\", \"-o\", \"yaml\"); err != nil {\n\tif strings.Contains(err.Error(), \"unable to marshal YAML\") {\n\t\t// fallback to JSON output and convert with yq\n\t\treturn runKops(\"get\", \"keypairs\", \"-o\", \"json\")\n\t}\n\treturn err\n}","preventionTips":["Prefer -o json for machine consumption; convert to YAML with yq if needed.","Keep the kops build clean of local keypairItem type modifications.","Rebuild with a clean module cache after dependency upgrades.","Capture the wrapped marshal error text when reporting issues."],"tags":["yaml","serialization","cli"],"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"}