{"record":{"id":"f9c8747c58a45198","repo":"kubernetes/kops","slug":"marshaling-to-yaml-for-v-w","errorCode":null,"errorMessage":"marshaling to yaml for %v: %w","messagePattern":"marshaling to yaml for (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dump/resourcedumper.go","lineNumber":251,"sourceCode":"\t\t\tresults <- resourceDumpResult{\n\t\t\t\terr: fmt.Errorf(\"creating accessor for %v: %w\", job, err),\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tcontents, err := resourceList.MarshalJSON()\n\t\tif err != nil {\n\t\t\tresults <- resourceDumpResult{\n\t\t\t\terr: fmt.Errorf(\"marshaling to json for %v: %w\", job, err),\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch d.output {\n\t\tcase \"yaml\":\n\t\t\tcontents, err = yaml.JSONToYAML(contents)\n\t\t\tif err != nil {\n\t\t\t\tresults <- resourceDumpResult{\n\t\t\t\t\terr: fmt.Errorf(\"marshaling to yaml for %v: %w\", job, err),\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t\t_, err = resFile.Write(contents)\n\t\tif err != nil {\n\t\t\tresults <- resourceDumpResult{\n\t\t\t\terr: fmt.Errorf(\"encoding resources for %v: %w\", job, err),\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tresults <- resourceDumpResult{}\n\t}\n}\n\nfunc maskObject(obj runtime.Object) error {\n\tif obj.GetObjectKind().GroupVersionKind() == (schema.GroupVersionKind{Group: \"\", Version: \"v1\", Kind: \"Secret\"}) {\n\t\tunstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/dump/resourcedumper.go#L233-L269","documentation":"When --output (d.output) is \"yaml\", dumpGVRNamespaces converts the marshaled JSON to YAML using sigs.k8s.io/yaml's JSONToYAML. If the conversion fails, the error is wrapped as \"marshaling to yaml for %v: %w\". Since the input is already valid JSON produced one step earlier, this usually means the JSON contains constructs sigs.k8s.io/yaml cannot represent (rare, e.g. invalid UTF-8 or pathological numeric values).","triggerScenarios":"yaml.JSONToYAML(contents) fails on JSON that sigs.k8s.io/yaml (via gopkg.in/yaml.v2) cannot encode: invalid UTF-8 bytes in resource fields, out-of-range numbers, or deeply/irregularly typed unstructured data from a misbehaving API server.","commonSituations":"Custom resources containing invalid UTF-8 strings or unusual numeric values; dumping with -o yaml against an API server returning corrupt data; older sigs.k8s.io/yaml versions with conversion bugs.","solutions":["Dump with --out json instead of yaml to bypass JSONToYAML conversion.","Inspect the offending resource's fields for invalid UTF-8 or odd values and fix/delete that object.","Upgrade kOps to pick up newer sigs.k8s.io/yaml with fixed conversion handling.","Check the serving API server/CRD for data corruption and correct the source of the bad data."],"exampleFix":"// before\nkops toolbox dump --out yaml\n// after (workaround)\nkops toolbox dump --out json","handlingStrategy":"fallback","validationCode":"// Pre-check that the JSON payload converts cleanly before writing\ncanonical, err := yaml.JSONToYAML(jsonBytes)\nif err != nil {\n  log.Printf(\"yaml conversion failed (%v); falling back to json output\", err)\n  canonical = jsonBytes\n}","typeGuard":null,"tryCatchPattern":"contents, err := yaml.JSONToYAML(jsonBytes)\nif err != nil {\n  log.Printf(\"yaml conversion failed: %v; writing raw json instead\", err)\n  contents = jsonBytes // fallback to json output\n}","preventionTips":["Prefer --out json when dumping clusters containing exotic custom resources.","Validate CR string fields for valid UTF-8 at admission time (CEL/webhook validation).","Keep sigs.k8s.io/yaml upgraded; conversion bugs get fixed upstream.","Spot-check problematic resources with `kubectl get -o yaml` before large dumps."],"tags":["yaml","serialization","kubernetes","kops"],"backgroundTag":"yaml-conversion-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"}