{"record":{"id":"8e08de3b6efe0af6","repo":"grpc-ecosystem/grpc-gateway","slug":"empty-mime-type","errorCode":null,"errorMessage":"empty MIME type","messagePattern":"empty MIME type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"runtime/marshaler_registry.go","lineNumber":77,"sourceCode":"\t\tinbound = mux.marshalers.mimeMap[MIMEWildcard]\n\t}\n\tif outbound == nil {\n\t\toutbound = inbound\n\t}\n\n\treturn inbound, outbound\n}\n\n// marshalerRegistry is a mapping from MIME types to Marshalers.\ntype marshalerRegistry struct {\n\tmimeMap map[string]Marshaler\n}\n\n// add adds a marshaler for a case-sensitive MIME type string (\"*\" to match any\n// MIME type).\nfunc (m marshalerRegistry) add(mime string, marshaler Marshaler) error {\n\tif len(mime) == 0 {\n\t\treturn errors.New(\"empty MIME type\")\n\t}\n\n\tm.mimeMap[mime] = marshaler\n\n\treturn nil\n}\n\n// makeMarshalerMIMERegistry returns a new registry of marshalers.\n// It allows for a mapping of case-sensitive Content-Type MIME type string to runtime.Marshaler interfaces.\n//\n// For example, you could allow the client to specify the use of the runtime.JSONPb marshaler\n// with an \"application/jsonpb\" Content-Type and the use of the runtime.JSONBuiltin marshaler\n// with an \"application/json\" Content-Type.\n// \"*\" can be used to match any Content-Type.\n// This can be attached to a ServerMux with the marshaler option.\nfunc makeMarshalerMIMERegistry() marshalerRegistry {\n\treturn marshalerRegistry{\n\t\tmimeMap: map[string]Marshaler{","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/grpc-ecosystem/grpc-gateway/blob/a58a4436a376a4bcc7d8f10c4d4f919a8438bba9/runtime/marshaler_registry.go#L59-L95","documentation":"This error is returned by marshalerRegistry.add when registering a Marshaler with an empty MIME type string. The registry keys marshalers by a case-sensitive MIME type (\"*\" matches any), so an empty key would create an unusable, unmatchable entry. The library refuses the registration instead of silently storing it.","triggerScenarios":"Calling Runtime(Registry).RegisterMarshaler, runtime.NewMarshalerRegistry, or marshalerRegistry.add with (\"\", someMarshaler), or with a Marshaler whose ContentType() method returns an empty string.","commonSituations":"A custom Marshaler implementation whose ContentType() returns \"\" when uninitialized or misconfigured; building marshaler maps programmatically from config data where a MIME type field was omitted; typos leaving a struct field empty.","solutions":["Set a valid, non-empty MIME type string (e.g. \"application/json\" or \"application/proto\"; use \"*\" for a wildcard) when calling add/RegisterMarshaler","Fix the custom Marshaler's ContentType() method so it returns a concrete MIME type in all code paths","Validate configured MIME types before passing them to the registry"],"exampleFix":"// before\nreg.add(\"\", myMarshaler)\n// after\nreg.add(\"application/vnd.my+json\", myMarshaler)","handlingStrategy":"validation","validationCode":"if mime == \"\" {\n    return fmt.Errorf(\"marshaler requires a non-empty MIME type, got %q\", mime)\n}\nreg.add(mime, marshaler)","typeGuard":"func hasContentType(m runtime.Marshaler) bool {\n    return m.ContentType() != \"\"\n}","tryCatchPattern":null,"preventionTips":["Always return a concrete MIME string from custom Marshaler.ContentType(), never a bare return \"\"","Use \"*\" deliberately for wildcard fallback marshalers","Unit-test custom marshalers assert ContentType() != \"\""],"tags":["go","grpc-gateway","marshaler","mime-type"],"backgroundTag":"empty-mime-type","analyzedSha":"a58a4436a376a4bcc7d8f10c4d4f919a8438bba9","analyzedAt":"2026-09-02T10:28:31.537Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}