{"record":{"id":"fb2dbb5aea2e68c8","repo":"kubernetes/kops","slug":"no-serializer-for-q","errorCode":null,"errorMessage":"no serializer for %q","messagePattern":"no serializer for %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/kopscodecs/codecs.go","lineNumber":55,"sourceCode":"\tCodecs         = serializer.NewCodecFactory(Scheme)\n\tParameterCodec = runtime.NewParameterCodec(Scheme)\n)\n\nfunc init() {\n\tmetav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: \"v1\"})\n\tinstall.Install(Scheme)\n}\n\n// ToVersionedYaml encodes the object to YAML\nfunc ToVersionedYaml(obj runtime.Object) ([]byte, error) {\n\treturn ToVersionedYamlWithVersion(obj, v1alpha2.SchemeGroupVersion)\n}\n\n// ToMediaTypeWithVersion encodes the object to the specified mediaType, in a specified API version\nfunc ToMediaTypeWithVersion(obj runtime.Object, mediaType string, gv runtime.GroupVersioner) ([]byte, error) {\n\te, ok := runtime.SerializerInfoForMediaType(Codecs.SupportedMediaTypes(), mediaType)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"no serializer for %q\", mediaType)\n\t}\n\n\t_, isUnstructured := obj.(*unstructured.Unstructured)\n\tvar w bytes.Buffer\n\tif isUnstructured {\n\t\terr := e.Serializer.Encode(obj, &w)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error encoding %T with unstructured encoder: %w\", obj, err)\n\t\t}\n\t} else {\n\t\tencoder := Codecs.EncoderForVersion(e.Serializer, gv)\n\t\tif err := encoder.Encode(obj, &w); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error encoding %T with structured encoder: %w\", obj, err)\n\t\t}\n\t}\n\treturn w.Bytes(), nil\n}\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/kopscodecs/codecs.go#L37-L73","documentation":"kopscodecs.ToMediaTypeWithVersion looks up a serializer matching the requested mediaType (e.g. \"application/yaml\", \"application/json\") among Codecs.SupportedMediaTypes(). If no registered serializer supports that media type string, it fails before encoding. The mediaType string must exactly match a supported entry.","triggerScenarios":"Calling ToMediaTypeWithVersion (directly or via ToVersionedYamlWithVersion / ToVersionedJSONWithVersion) with a mediaType string like \"text/yaml\", \"application/yaml; charset=utf-8\", or a typo rather than an exactly-supported media type.","commonSituations":"Passing a media type from an HTTP Content-Type header including parameters; using a MIME type from config that differs from the codecs' registered names; kops API version changes that alter supported media types.","solutions":["Use exactly \"application/yaml\" or \"application/json\" as the mediaType.","Iterate Codecs.SupportedMediaTypes() to pick a valid media type instead of hardcoding.","Strip parameters (charset etc.) from any media type taken from headers/config before calling."],"exampleFix":"// before\nb, err := kopscodecs.ToMediaTypeWithVersion(obj, \"text/yaml\", gv)\n// after\nb, err := kopscodecs.ToMediaTypeWithVersion(obj, \"application/yaml\", gv)","handlingStrategy":"validation","validationCode":"func supportedMediaType(mt string) bool {\n\tfor _, si := range kopscodecs.Codecs.SupportedMediaTypes() {\n\t\tif si.MediaType == mt {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n// call before: if !supportedMediaType(mediaType) { normalize to \"application/yaml\" or \"application/json\" }","typeGuard":null,"tryCatchPattern":"b, err := kopscodecs.ToMediaTypeWithVersion(obj, mediaType, gv)\nif err != nil {\n\treturn fmt.Errorf(\"unsupported media type %q: %w\", mediaType, err)\n}","preventionTips":["Use only the exact strings from SupportedMediaTypes().","Strip media-type parameters before passing values from headers/config.","Never hardcode alternate spellings like \"text/yaml\"."],"tags":["kubernetes","serialization","media-type"],"backgroundTag":"no-serializer-for-media-type","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"}