{"record":{"id":"021ca3d9b4368524","repo":"kubernetes/kops","slug":"unable-to-marshal-yaml-v-021ca3","errorCode":null,"errorMessage":"unable to marshal YAML: %v","messagePattern":"unable to marshal YAML: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/validate_cluster.go","lineNumber":213,"sourceCode":"\t\t\tconsecutive = 0\n\t\t\tif options.wait > 0 {\n\t\t\t\tklog.Warningf(\"(will retry): unexpected error during validation: %v\", err)\n\t\t\t\ttime.Sleep(options.interval)\n\t\t\t\tcontinue\n\t\t\t} else {\n\t\t\t\treturn nil, fmt.Errorf(\"unexpected error during validation: %v\", err)\n\t\t\t}\n\t\t}\n\n\t\tswitch options.output {\n\t\tcase OutputTable:\n\t\t\tif err := validateClusterOutputTable(result, cluster, instanceGroups, out); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\tcase OutputYaml:\n\t\t\ty, err := yaml.Marshal(result)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"unable to marshal YAML: %v\", err)\n\t\t\t}\n\t\t\tif _, err := out.Write(y); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"error writing to output: %v\", err)\n\t\t\t}\n\t\tcase OutputJSON:\n\t\t\tj, err := json.Marshal(result)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"unable to marshal JSON: %v\", err)\n\t\t\t}\n\t\t\tif _, err := out.Write(j); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"error writing to output: %v\", err)\n\t\t\t}\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"unknown output format: %q\", options.output)\n\t\t}\n\n\t\tif len(result.Failures) == 0 {\n\t\t\tconsecutive++","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/validate_cluster.go#L195-L231","documentation":"This error is raised when yaml.Marshal(result) fails while rendering validation results in --output yaml mode. yaml.Marshal of a plain validation result struct essentially never fails in practice; failure implies an unmarshalable type in the result (e.g. channel, func field) or a corrupted result produced by the validator.","triggerScenarios":"`kops validate cluster -o yaml` where the validation result struct contains a value the YAML encoder cannot serialize.","commonSituations":"A kops version mismatch or patched binary injecting an unsupported field into the result struct; a custom validator plugin returning unserializable data; extremely rare — usually indicates a kops bug.","solutions":["Re-run with default table output or -o json to get results and file a bug if only yaml fails.","Confirm kops binary version matches the cluster's kops version; upgrade or rebuild the binary.","Check for locally patched kops builds or plugins altering the validation result type.","Report to kops maintainers with the printed %v cause if it persists with official binaries."],"exampleFix":"// before\nkops validate cluster -o yaml\n// after\nkops validate cluster -o json","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"result, err := runValidateCluster(ctx, options)\nif err != nil && strings.Contains(err.Error(), \"unable to marshal YAML\") {\n\t// fall back to JSON or table output\n\treturn runValidateCluster(ctx, withOutput(options, OutputJSON))\n}","preventionTips":["Prefer -o json; YAML marshalling of validation results is a rarer path.","Avoid patched kops builds that alter the result struct.","Report reproducible marshal failures upstream as kops bugs.","Pin kops version to the release matching your cluster."],"tags":["yaml","serialization","kops"],"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"}