{"record":{"id":"75d6acbccceb66e0","repo":"kubernetes/kops","slug":"error-marshalling-s-s-w","errorCode":null,"errorMessage":"error marshalling %s/%s: %w","messagePattern":"error marshalling (.+?)/(.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/toolbox/clusterapi/generate_machinedeployment.go","lineNumber":234,"sourceCode":"\t\tName:              options.Name,\n\t\tReplicas:          options.Replicas,\n\t\tZones:             zones,\n\t\tMachineType:       instanceType,\n\t\tSubnet:            subnet,\n\t\tImage:             image,\n\t\tKubernetesVersion: kubernetesVersion,\n\t\tRole:              role,\n\t}\n\n\tobjects, err := b.BuildObjects(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfor i, obj := range objects {\n\t\tb, err := yaml.Marshal(obj.Object)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error marshalling %s/%s: %w\", obj.GetKind(), obj.GetName(), err)\n\t\t}\n\t\tif i != 0 {\n\t\t\tfmt.Fprintf(out, \"---\\n\")\n\t\t}\n\t\tout.Write(b)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":216,"sourceCodeEnd":244,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/commands/toolbox/clusterapi/generate_machinedeployment.go#L216-L244","documentation":"After generating the MachineDeployment and related objects, the command serializes each unstructured object to YAML with `yaml.Marshal`. If sigs.k8s.io/yaml cannot marshal an object's underlying map (e.g. values that cannot be converted to JSON-compatible types), it wraps and returns this error naming the kind and name of the offending object.","triggerScenarios":"An object in the generated `objects` slice contains data that cannot round-trip through JSON (e.g. non-string map keys of unsupported types, invalid nested values) when `RunGenerateMachineDeployment` writes output.","commonSituations":"Rare in practice since objects are built from typed kOps/k8s APIs; can surface with schema drift after a kOps/k8s API version upgrade where generated fields hold unexpected types.","solutions":["Check the wrapped inner error for the exact field/type that failed marshalling","Upgrade kops to a version matching your cluster/k8s API versions so generated objects match expected schemas","Re-run with a different --output path/permissions excluded; if persistent, regenerate objects with a smaller scope (single instance group) to isolate the bad object"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := RunGenerateMachineDeployment(ctx, f, out, opts); err != nil {\n    if strings.Contains(err.Error(), \"error marshalling\") {\n        log.Printf(\"generated object could not be serialized: %v\", err)\n        // inspect kind/name embedded in message, regenerate or upgrade kops\n    }\n    return err\n}","preventionTips":["Keep kops and kubernetes API dependency versions aligned","Validate output with `--dry-run` scopes to isolate the offending object","Avoid injecting raw/untyped data into generated objects"],"tags":["yaml","serialization","cluster-api","cli"],"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"}