{"record":{"id":"a626f810cb01d453","repo":"micro/go-micro","slug":"unrecognized-message-type-v","errorCode":null,"errorMessage":"unrecognized message type: %v","messagePattern":"unrecognized message type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"codec/jsonrpc/jsonrpc.go","lineNumber":44,"sourceCode":"func (j *jsonCodec) String() string {\n\treturn \"json-rpc\"\n}\n\nfunc (j *jsonCodec) Write(m *codec.Message, b interface{}) error {\n\tswitch m.Type {\n\tcase codec.Request:\n\t\treturn j.c.Write(m, b)\n\tcase codec.Response, codec.Error:\n\t\treturn j.s.Write(m, b)\n\tcase codec.Event:\n\t\tdata, err := json.Marshal(b)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\t_, err = j.rwc.Write(data)\n\t\treturn err\n\tdefault:\n\t\treturn fmt.Errorf(\"unrecognized message type: %v\", m.Type)\n\t}\n}\n\nfunc (j *jsonCodec) ReadHeader(m *codec.Message, mt codec.MessageType) error {\n\tj.buf.Reset()\n\tj.mt = mt\n\n\tswitch mt {\n\tcase codec.Request:\n\t\treturn j.s.ReadHeader(m)\n\tcase codec.Response:\n\t\treturn j.c.ReadHeader(m)\n\tcase codec.Event:\n\t\t_, err := io.Copy(j.buf, j.rwc)\n\t\treturn err\n\tdefault:\n\t\treturn fmt.Errorf(\"unrecognized message type: %v\", mt)\n\t}","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/codec/jsonrpc/jsonrpc.go#L26-L62","documentation":"The jsonrpc codec's Write method switches on the codec.MessageType (Request, Response, etc.) to decide how to serialize the message. Any message type it does not explicitly handle falls through to default and yields this error, meaning the codec cannot encode the given message kind.","triggerScenarios":"Calling Write on a jsonrpc codec with a message whose Type is not one of the handled types (e.g. codec.Event if unhandled, or a zero-value MessageType).","commonSituations":"Custom transport code sending raw codec.Message values with a hand-set Type; framework internals publishing events through a client configured with the jsonrpc codec that does not support that message type; constructing codec.Message manually in tests.","solutions":["Use a message Type supported by the jsonrpc codec (Request/Response as implemented).","Switch to the appropriate codec for that message type (e.g. bytes or grpc codec supports more flows).","Verify the client/server configuration is not routing Event/Publish traffic through the jsonrpc codec.","Check that codec.Message.Type is set explicitly, not left as zero value."],"exampleFix":"// before\nmsg.Type = codec.Event\njcodec.Write(msg, body)\n// after\nmsg.Type = codec.Request\njcodec.Write(msg, body)","handlingStrategy":"type-guard","validationCode":"func jsonrpcSupports(mt codec.MessageType) bool {\n\treturn mt == codec.Request || mt == codec.Response || mt == codec.Event\n}","typeGuard":"func isJsonrpcWritable(m *codec.Message) bool {\n\treturn m != nil && jsonrpcSupports(m.Type)\n}","tryCatchPattern":"if err := c.Write(msg, body); err != nil {\n\tif strings.HasPrefix(err.Error(), \"unrecognized message type\") {\n\t\t// unsupported MessageType for this codec; use another codec or fix msg.Type\n\t}\n\treturn err\n}","preventionTips":["Set codec.Message.Type explicitly and to a supported value.","Do not route Event/publish traffic through codecs that do not implement it.","Prefer built-in transports that assign message types for you.","Add a switch-level test enumerating every MessageType your flow uses."],"tags":["jsonrpc","codec","message-type"],"backgroundTag":"unsupported-codec-message-type","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}