{"record":{"id":"2043d562ef00a7be","repo":"dianping/cat","slug":"unsupported-message-s","errorCode":null,"errorMessage":"Unsupported message(%s).","messagePattern":"Unsupported message\\((.+?)\\)\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"cat-core/src/main/java/com/dianping/cat/message/codec/NativeMessageCodec.java","lineNumber":154,"sourceCode":"\t\t\tCodec.TRANSACTION_START.encode(ctx, buf, msg);\n\n\t\t\tfor (Message child : children) {\n\t\t\t\tif (child != null) {\n\t\t\t\t\tencodeMessage(ctx, buf, child);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tCodec.TRANSACTION_END.encode(ctx, buf, msg);\n\t\t} else if (msg instanceof Event) {\n\t\t\tCodec.EVENT.encode(ctx, buf, msg);\n\t\t} else if (msg instanceof Metric) {\n\t\t\tCodec.METRIC.encode(ctx, buf, msg);\n\t\t} else if (msg instanceof Heartbeat) {\n\t\t\tCodec.HEARTBEAT.encode(ctx, buf, msg);\n\t\t} else if (msg instanceof Trace) {\n\t\t\tCodec.TRACE.encode(ctx, buf, msg);\n\t\t} else {\n\t\t\tthrow new RuntimeException(String.format(\"Unsupported message(%s).\", msg));\n\t\t}\n\t}\n\n\tenum Codec {\n\t\tHEADER {\n\t\t\t@Override\n\t\t\tprotected Message decode(Context ctx, ByteBuf buf) {\n\t\t\t\tMessageTree tree = ctx.getMessageTree();\n\t\t\t\tString version = ctx.getVersion(buf);\n\n\t\t\t\tif (ID.equals(version)) {\n\t\t\t\t\ttree.setDomain(ctx.readString(buf));\n\t\t\t\t\ttree.setHostName(ctx.readString(buf));\n\t\t\t\t\ttree.setIpAddress(ctx.readString(buf));\n\t\t\t\t\ttree.setThreadGroupName(ctx.readString(buf));\n\t\t\t\t\ttree.setThreadId(ctx.readString(buf));\n\t\t\t\t\ttree.setThreadName(ctx.readString(buf));\n\t\t\t\t\ttree.setMessageId(ctx.readString(buf));","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-core/src/main/java/com/dianping/cat/message/codec/NativeMessageCodec.java#L136-L172","documentation":"NativeMessageCodec's encodeMessage throws RuntimeException(\"Unsupported message(%s).\") — note it interpolates msg.toString(), not the class — when the object to encode is none of Transaction/Event/Metric/Heartbeat/Trace. This is the encode-side twin of the decode-side type-tag guard: the binary wire format simply has no tag for other Message implementations.","triggerScenarios":"Encoding a MessageTree whose children contain a bare Message implementation (mock, proxy, or plugin class) rather than one of the five built-in kinds; the toString() in the message identifies the offending object.","commonSituations":"Unit tests with mocked Message objects fed into the real codec; custom message classes from home-grown extensions; objects wrapped by dynamic proxies (AOP) that no longer instanceOf the known types.","solutions":["Read the object description in the exception message to identify which child is unsupported.","Replace the custom implementation with DefaultEvent/DefaultTransaction/etc. so the standard tags apply.","Sanitize the tree before send: drop or convert unknown message kinds.","Upgrade CAT on both sides if a legitimate newer message type is involved."],"exampleFix":"// before\nMessage raw = mock(Message.class); // not a known subtype\ncodec.encode(treeWith(raw)); // throws\n\n// after\nDefaultEvent ev = new DefaultEvent(\"Custom\", \"value\");\ncodec.encode(treeWith(ev)); // 'E' tag","handlingStrategy":"type-guard","validationCode":"List<Message> keep = new ArrayList<>();\nfor (Message m : tree.getMessages())\n    if (m instanceof Transaction || m instanceof Event || m instanceof Metric || m instanceof Heartbeat || m instanceof Trace) keep.add(m);\ntree.getMessages().retainAll(keep);","typeGuard":"boolean encodable(Message m) { return m instanceof Transaction || m instanceof Event || m instanceof Metric || m instanceof Heartbeat || m instanceof Trace; }","tryCatchPattern":null,"preventionTips":["Ban bare Message implementations in code review; require Default* subclasses.","Keep mocks out of real codec paths in tests."],"tags":["encoding","binary-protocol","message-tree"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}