{"record":{"id":"24991a00f8da83bc","repo":"kubernetes/kops","slug":"unable-to-marshal-yaml-v-24991a","errorCode":null,"errorMessage":"unable to marshal YAML: %v","messagePattern":"unable to marshal YAML: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/get_sshpublickeys.go","lineNumber":123,"sourceCode":"\t\titems = append(items, item)\n\t}\n\n\tswitch options.Output {\n\n\tcase OutputTable:\n\t\tif len(items) == 0 {\n\t\t\treturn fmt.Errorf(\"no SSH public key found\")\n\t\t}\n\t\tt := &tables.Table{}\n\t\tt.AddColumn(\"ID\", func(i *SSHKeyItem) string {\n\t\t\treturn i.ID\n\t\t})\n\t\treturn t.Render(items, out, \"ID\")\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\tdefault:\n\t\treturn fmt.Errorf(\"unknown output format: %q\", options.Output)\n\t}\n\n\treturn nil\n}","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get_sshpublickeys.go#L105-L141","documentation":"In YAML output mode, `kops get sshpublickeys` serializes the collected SSHKeyItem slice with gopkg.in/yaml.v2/api Marshal. Marshal of these plain structs essentially never fails; if it does (unserializable types introduced by code changes), the command returns \"unable to marshal YAML: %v\".","triggerScenarios":"Practically only when the SSHKeyItem struct gains a field whose type cannot be YAML-serialized (e.g. func, chan, or a cycle) after a code change; not user-triggerable via flags.","commonSituations":"Custom builds/patches of kOps that altered the item struct; a bug in a fork; otherwise almost never seen by end users.","solutions":["Check the wrapped error after 'unable to marshal YAML' to identify the offending field/type","If you patched the code, ensure all new fields on SSHKeyItem are YAML-serializable (add yaml tags or omit the field)","Fall back to `-o json` to see if JSON marshaling succeeds and isolate the YAML-specific issue"],"exampleFix":"// before\nfoo func() `yaml:\"foo\"`\n// after\nFoo string `yaml:\"foo,omitempty\"` // replace unserializable field type","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := runGetSSHPublicKeys(opts); err != nil {\n\tif strings.HasPrefix(err.Error(), \"unable to marshal YAML:\") {\n\t\t// fall back to JSON output\n\t\topts.Output = OutputJSON\n\t\treturn runGetSSHPublicKeys(opts)\n\t}\n\treturn err\n}","preventionTips":["Keep SSHKeyItem fields YAML-serializable (no func/chan/cycles)","Add yaml/json struct tags to new fields","Test all output formats (table/yaml/json) after changing item structs"],"tags":["cli","yaml","serialization"],"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"}