{"record":{"id":"8727e0e5cf75f40a","repo":"kubernetes/kops","slug":"error-marshaling-yaml-v","errorCode":null,"errorMessage":"error marshaling yaml: %v","messagePattern":"error marshaling yaml: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/get.go","lineNumber":108,"sourceCode":"type marshalFunc func(obj runtime.Object) ([]byte, error)\n\nfunc marshalToWriter(obj runtime.Object, marshal marshalFunc, w io.Writer) error {\n\tb, err := marshal(obj)\n\tif err != nil {\n\t\treturn err\n\t}\n\t_, err = w.Write(b)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error writing to stdout: %v\", err)\n\t}\n\treturn nil\n}\n\n// obj must be a pointer to a marshalable object\nfunc marshalYaml(obj runtime.Object) ([]byte, error) {\n\ty, err := kopscodecs.ToVersionedYaml(obj)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error marshaling yaml: %v\", err)\n\t}\n\treturn y, nil\n}\n\n// obj must be a pointer to a marshalable object\nfunc marshalJSON(obj runtime.Object) ([]byte, error) {\n\tj, err := kopscodecs.ToVersionedJSON(obj)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error marshaling json: %v\", err)\n\t}\n\treturn j, nil\n}\n","sourceCodeStart":90,"sourceCodeEnd":121,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get.go#L90-L121","documentation":"marshalYaml converts a runtime.Object to versioned YAML via kopscodecs.ToVersionedYaml; a conversion or serialization failure (unsupported object, bad GVK, unmarshalable field) is wrapped as \"error marshaling yaml\". It backs the -o yaml output of `kops get`.","triggerScenarios":"`kops get -o yaml` on an object the codec cannot convert to the versioned YAML shape — e.g. an internal-typed object lacking a registered conversion, or an object containing fields the yaml serializer cannot represent.","commonSituations":"Version skew between kops CLI and state-store objects (newer fields from a newer kops not convertible by the current codec); a corrupted or hand-edited manifest in the state store; fetching resources whose scheme registration is missing in the CLI build.","solutions":["Read the wrapped %v detail to find the offending field/type and fix the stored object (kops get -o json often still works for diagnosis)","Align the kops CLI version with the cluster's state-store version (upgrade/downgrade the binary)","Use -o json output as a fallback and convert to YAML yourself with yq","Repair or remove the corrupt manifest in the state store (S3/object store) if a single object is broken"],"exampleFix":"// before\nkops get instancegroup nodes -o yaml   # codec conversion fails on new field\n// after (workaround)\nkops get instancegroup nodes -o json | yq -P '.' ","handlingStrategy":"try-catch","validationCode":"// probe with JSON first; JSON marshal failures predict YAML failures\nif _, err := kopscodecs.ToVersionedYaml(obj); err != nil {\n    return fmt.Errorf(\"object not serializable to yaml: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"y, err := marshalYaml(obj)\nif err != nil {\n    if strings.Contains(err.Error(), \"error marshaling yaml\") {\n        // fall back to JSON output: b, jerr := marshalJSON(obj)\n    }\n}","preventionTips":["Keep the kops CLI version aligned with the state-store version","Use -o json to diagnose objects that fail YAML conversion","Don't hand-edit state-store manifests with unknown fields","Upgrade the binary if errors mention unregistered types or unknown conversion paths"],"tags":["yaml","serialization","codec"],"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"}