{"record":{"id":"71fe7f3fa65d44e1","repo":"kubernetes/kops","slug":"unable-to-marshal-yaml-v","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_assets.go","lineNumber":161,"sourceCode":"\t}\n\n\tif options.Copy {\n\t\terr := assetcopy.Copy(updateClusterResults.ImageAssets, updateClusterResults.FileAssets, f.VFSContext(), updateClusterResults.Cluster)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tswitch options.Output {\n\tcase OutputTable:\n\t\tif err = imageOutputTable(result.Images, out); err != nil {\n\t\t\treturn err\n\t\t}\n\t\treturn fileOutputTable(result.Files, out)\n\tcase OutputYaml:\n\t\ty, err := yaml.Marshal(result)\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(result)\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(\"unsupported output format: %q\", options.Output)\n\t}\n\n\treturn nil\n}","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get_assets.go#L143-L179","documentation":"RunGetAssets uses sigs.k8s.io/yaml.Marshal to serialize the AssetResult (images and file assets) for `kops get assets -o yaml`, and wraps any marshal failure with this message. Because AssetResult contains only plain string-slice structs this is rare, but a marshaling failure (unsupported types, cycle, or writer-side issues surfaced by the YAML library) triggers it.","triggerScenarios":"`kops get assets -o yaml` where yaml.Marshal(result) returns an error — typically unexpected data types inside the result or a failure of the underlying JSON-based YAML conversion.","commonSituations":"Modified/patched builds where AssetResult gained unmarshalable fields; corrupted asset URLs (e.g. nil-adjacent data from a dry run) producing values the marshaller cannot handle; unusual plugin-added assets.","solutions":["Read the wrapped inner error to identify which value failed to convert","Ensure the asset data comes from a successful RunUpdateCluster dry run (check the preceding error path)","Retry with -o json or the default table output to isolate whether only YAML serialization fails","Update kops if the failure comes from a patched or modified binary"],"exampleFix":"// before\ny, err := yaml.Marshal(result)\nif err != nil { return fmt.Errorf(\"unable to marshal YAML: %v\", err) }\n// after\nj, err := json.Marshal(result)\nif err != nil { return err }\ny, err := yaml.JSONToYAML(j) // sigs.k8s.io/yaml goes through JSON","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"y, err := yaml.Marshal(result)\nif err != nil {\n    // fall back to JSON which supports more types\n    j, jerr := json.Marshal(result)\n    if jerr != nil {\n        return fmt.Errorf(\"unable to marshal YAML: %v (json fallback: %v)\", err, jerr)\n    }\n    y, _ = yaml.JSONToYAML(j)\n}","preventionTips":["Keep AssetResult fields as plain serializable types","Confirm the dry-run update succeeded before formatting output","Fall back to table/json output if YAML path fails","Pin upstream kops binaries rather than patched forks"],"tags":["yaml","serialization","assets","cli"],"backgroundTag":"yaml-serialize-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"}