{"record":{"id":"f375ec6cbbf9f21b","repo":"spring-projects/spring-ai","slug":"unsupported-message-type","errorCode":null,"errorMessage":"Unsupported message type: ","messagePattern":"Unsupported message type: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"memory-repositories/spring-ai-model-chat-memory-repository-mongodb/src/main/java/org/springframework/ai/chat/memory/repository/mongo/MongoChatMemoryRepository.java","lineNumber":107,"sourceCode":"\tpublic void deleteByConversationId(String conversationId) {\n\t\tthis.mongoTemplate.remove(Query.query(Criteria.where(\"conversationId\").is(conversationId)), Conversation.class);\n\t}\n\n\tpublic static @Nullable Message mapMessage(Conversation conversation) {\n\t\tfinal String content = Objects.requireNonNullElse(conversation.message().content(), \"\");\n\t\treturn switch (conversation.message().type()) {\n\t\t\tcase \"USER\" -> UserMessage.builder().text(content).metadata(conversation.message().metadata()).build();\n\t\t\tcase \"ASSISTANT\" ->\n\t\t\t\tAssistantMessage.builder().content(content).properties(conversation.message().metadata()).build();\n\t\t\tcase \"SYSTEM\" -> SystemMessage.builder().text(content).metadata(conversation.message().metadata()).build();\n\t\t\t// this implementation doesn't support tool calls message persistence, so\n\t\t\t// TOOL rows are filtered out by the caller\n\t\t\tcase \"TOOL\" -> null;\n\t\t\tdefault -> {\n\t\t\t\tif (logger.isWarnEnabled()) {\n\t\t\t\t\tlogger.warn(\"Unsupported message type: \" + conversation.message().type());\n\t\t\t\t}\n\t\t\t\tthrow new IllegalStateException(\"Unsupported message type: \" + conversation.message().type());\n\t\t\t}\n\t\t};\n\t}\n\n\tpublic static Builder builder() {\n\t\treturn new Builder();\n\t}\n\n\tpublic final static class Builder {\n\n\t\tprivate @Nullable MongoTemplate mongoTemplate;\n\n\t\tprivate Builder() {\n\t\t}\n\n\t\tpublic Builder mongoTemplate(MongoTemplate mongoTemplate) {\n\t\t\tthis.mongoTemplate = mongoTemplate;\n\t\t\treturn this;","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/memory-repositories/spring-ai-model-chat-memory-repository-mongodb/src/main/java/org/springframework/ai/chat/memory/repository/mongo/MongoChatMemoryRepository.java#L89-L125","documentation":"MongoChatMemoryRepository.mapMessage() maps stored documents to Message objects for USER/ASSISTANT/SYSTEM; TOOL documents map to null and are filtered by the caller. Any other type string logs a warning and throws IllegalStateException to flag unsupported or corrupt data.","triggerScenarios":"Reading a MongoDB chat-memory document whose 'type' field is not one of USER, ASSISTANT, SYSTEM, TOOL — e.g. documents written by another tool or a mismatched schema version.","commonSituations":"Another application shares the MongoDB collection and writes custom message types; manual document inserts; version skew between writer and reader.","solutions":["Find and fix/remove the document with the unsupported type (find documents where type is not in USER/ASSISTANT/SYSTEM/TOOL)","Align library versions across services sharing the collection","Pre-filter unsupported types at query time before mapping"],"exampleFix":"// before\ndb.chat_memory.insertOne({conversationId:'c1', type:'FUNCTION', ...}); // throws on read\n// after\ndb.chat_memory.insertOne({conversationId:'c1', type:'ASSISTANT', ...});","handlingStrategy":"validation","validationCode":"Document doc = collection.find(eq(\"conversationId\", id));\n// verify doc.getString(\"type\") in [USER, ASSISTANT, SYSTEM, TOOL] before mapping","typeGuard":"boolean isKnownType(String t) { return t != null && Set.of(\"USER\",\"ASSISTANT\",\"SYSTEM\",\"TOOL\").contains(t); }","tryCatchPattern":"try { messages = repo.findByConversationId(id); }\ncatch (IllegalStateException e) { messages = List.of(); logger.warn(\"Unsupported stored message type\", e); }","preventionTips":["Only let the Spring AI repository write to the chat-memory collection","Keep library versions aligned across services sharing MongoDB","Validate document types when migrating data into the collection"],"tags":["mongodb","chat-memory","message-type","state-exception"],"backgroundTag":"unsupported-enum-value","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}