{"record":{"id":"f2f797df1674fb94","repo":"kubernetes/kops","slug":"error-marshaling-manifest-to-yaml-w","errorCode":null,"errorMessage":"error marshaling manifest to yaml: %w","messagePattern":"error marshaling manifest to yaml: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/kubemanifest/manifest.go","lineNumber":131,"sourceCode":"\t\tif object.IsEmptyObject() {\n\t\t\tcontinue\n\t\t}\n\n\t\ty, err := object.ToYAML()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error re-marshaling manifest: %v\", err)\n\t\t}\n\n\t\tyamls = append(yamls, y)\n\t}\n\n\treturn bytes.Join(yamls, yamlSeparator), nil\n}\n\nfunc (m *Object) ToYAML() ([]byte, error) {\n\tb, err := yaml.Marshal(m.data)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error marshaling manifest to yaml: %w\", err)\n\t}\n\treturn b, nil\n}\n\nfunc (m *Object) MarshalJSON() ([]byte, error) {\n\tb, err := json.Marshal(m.data)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error marshaling manifest to json: %w\", err)\n\t}\n\treturn b, nil\n}\n\nfunc (m *Object) accept(visitor Visitor) error {\n\terr := visit(visitor, m.data, []string{}, func(v interface{}) {\n\t\tklog.Fatal(\"cannot mutate top-level data\")\n\t})\n\treturn err\n}","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/kubemanifest/manifest.go#L113-L149","documentation":"Object.ToYAML marshals the object's generic data map with sigs.k8s.io/yaml-compatible yaml.Marshal and wraps any marshal failure with this message. Because the data came from parsed YAML, failures are rare and typically indicate non-string map keys or values that cannot be represented in YAML/JSON.","triggerScenarios":"Calling Object.ToYAML directly, or any ObjectList.ToYAML/Build/Replace path, when m.data contains a value yaml.Marshal rejects (e.g. non-string-keyed maps, invalid types inserted programmatically).","commonSituations":"Custom manifest rewriting tools that put ints/complex values where the original YAML had different types; cyclic data structures from careless mutation.","solutions":["Ensure all values in Object data are JSON/YAML-compatible (string keys, scalars, slices, maps)","Print/inspect m.data (Object implements MarshalJSON) to find the offending value","Re-load the object from the original YAML to discard bad in-memory mutations","Check the wrapped error for the type and path that failed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// same yamlSafe check as errorIndex 1165, applied to m.data before marshaling\nif !yamlSafe(objData) { return fmt.Errorf(\"object data contains non-YAML values\") }\n","typeGuard":null,"tryCatchPattern":"b, err := obj.ToYAML()\nif err != nil {\n\treturn fmt.Errorf(\"failed to serialize manifest object: %w\", err)\n}\n","preventionTips":["Keep Object.data JSON/YAML-representable (string keys only)","Dump data via MarshalJSON for debugging before ToYAML","Round-trip test: parse YAML, marshal back, compare","Never assign funcs/channels into the data map"],"tags":["yaml","serialization","go"],"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"}