{"record":{"id":"355d7c9d0be371cb","repo":"dianping/cat","slug":"unrecognized-id-s-for-plain-text-message-codec","errorCode":null,"errorMessage":"Unrecognized id(%s) for plain text message codec!","messagePattern":"Unrecognized id\\((.+?)\\) for plain text message codec!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"cat-core/src/main/java/com/dianping/cat/message/codec/PlainTextMessageCodec.java","lineNumber":131,"sourceCode":"\t\tString threadName = helper.read(ctx, TAB);\n\t\tString messageId = helper.read(ctx, TAB);\n\t\tString parentMessageId = helper.read(ctx, TAB);\n\t\tString rootMessageId = helper.read(ctx, TAB);\n\t\tString sessionToken = helper.read(ctx, LF);\n\n\t\tif (VERSION.equals(id)) {\n\t\t\ttree.setDomain(domain);\n\t\t\ttree.setHostName(hostName);\n\t\t\ttree.setIpAddress(ipAddress);\n\t\t\ttree.setThreadGroupName(threadGroupName);\n\t\t\ttree.setThreadId(threadId);\n\t\t\ttree.setThreadName(threadName);\n\t\t\ttree.setMessageId(messageId);\n\t\t\ttree.setParentMessageId(parentMessageId);\n\t\t\ttree.setRootMessageId(rootMessageId);\n\t\t\ttree.setSessionToken(sessionToken);\n\t\t} else {\n\t\t\tthrow new RuntimeException(String.format(\"Unrecognized id(%s) for plain text message codec!\", id));\n\t\t}\n\t}\n\n\tprotected Message decodeLine(Context ctx, DefaultTransaction parent, Stack<DefaultTransaction> stack,\n\t      MessageTree tree) {\n\t\tBufferHelper helper = m_bufferHelper;\n\t\tbyte identifier = ctx.getBuffer().readByte();\n\t\tString timestamp = helper.read(ctx, TAB);\n\t\tString type = helper.read(ctx, TAB);\n\t\tString name = helper.read(ctx, TAB);\n\n\t\tswitch (identifier) {\n\t\tcase 't':\n\t\t\tDefaultTransaction transaction = new DefaultTransaction(type, name);\n\n\t\t\ttree.findOrCreateTransactions().add(transaction);\n\n\t\t\thelper.read(ctx, LF); // get rid of line feed","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-core/src/main/java/com/dianping/cat/message/codec/PlainTextMessageCodec.java#L113-L149","documentation":"PlainTextMessageCodec.decodeHeader validates the message-id token read from a PT1 payload against the expected VERSION constant and throws RuntimeException(\"Unrecognized id(%s) for plain text message codec!\") on mismatch. The plain-text protocol begins with a version/id line; a different token means the payload is not a PT1 message this codec can parse.","triggerScenarios":"Decoding a buffer whose header id token differs from VERSION — e.g. an NT1/NM1 binary payload reaching the plain-text codec, a corrupted header line, or a client with a different protocol revision.","commonSituations":"Wrong codec selected by a dispatcher; partial upgrades changing the id token; newline/tab framing issues that make the header token include stray bytes.","solutions":["Print the offending id from the exception; if it is 'NT1'/'NM1' the buffer was routed to the wrong codec.","Route by the 3-byte tag before choosing plain-text vs native vs metric decoding (CodecHandler does this — bypassing it causes this error).","Align client/server protocol versions.","Check that the tab-delimited header line is intact (not truncated, no double encoding)."],"exampleFix":"// before\nPlainTextMessageCodec codec = ...;\ntree = codec.decode(buf); // buf actually starts 'NT1' -> throws\n\n// after\nMessageTree tree = new CodecHandler(plainCodec, nativeCodec, metricDecoder).decode(buf);","handlingStrategy":"validation","validationCode":"String tag = buf.toString(buf.readerIndex(), 3, StandardCharsets.US_ASCII);\nMessageTree t = \"PT1\".equals(tag) ? plainCodec.decode(buf) : codecHandler.decode(buf);","typeGuard":null,"tryCatchPattern":"catch (RuntimeException e) { if (e.getMessage().contains(\"plain text message codec\")) { re-route buffer to CodecHandler.decode; } else throw e; }","preventionTips":["Always enter via CodecHandler; it performs tag dispatch for you.","Smoke-test routing with PT1/NT1/NM1 sample payloads after pipeline changes."],"tags":["protocol","text-decoding","dispatch","versioning"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}