{"record":{"id":"464ec9cb0c0e22c8","repo":"iflytek/astron-agent","slug":"data-not-found-464ec9","errorCode":"DATA_NOT_FOUND","errorMessage":"DATA_NOT_FOUND","messagePattern":"DATA_NOT_FOUND","errorType":"exception","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/controller/chat/ChatEnhanceController.java","lineNumber":111,"sourceCode":"     */\n    @Operation(summary = \"Unbind file's FileId and ChatId\")\n    @PostMapping(path = \"unbind-file\")\n    public ApiResult<Object> unbindFile(@RequestBody LongFileDto longFileDto) {\n        if (StringUtils.isBlank(longFileDto.getChatId())) {\n            throw new BusinessException(ResponseEnum.LONG_CONTENT_MISS_FILE_INFO);\n        }\n        Long chatId = Long.valueOf(longFileDto.getChatId());\n        String fileId = longFileDto.getFileId();\n        String linkIdString = longFileDto.getLinkId();\n\n        if (StringUtils.isBlank(fileId) && StringUtils.isBlank(linkIdString)) {\n            throw new BusinessException(ResponseEnum.LONG_CONTENT_MISS_FILE_INFO);\n        }\n        String uid = RequestContextUtil.getUID();\n        // Get the latest chat_id\n        List<ChatTreeIndex> chatTreeIndexList = chatListDataService.findChatTreeIndexByChatIdOrderById(chatId);\n        if (chatTreeIndexList.isEmpty()) {\n            throw new BusinessException(ResponseEnum.DATA_NOT_FOUND);\n        }\n        chatId = chatTreeIndexList.getFirst().getChildChatId();\n        ChatList chatList = chatListDataService.findByUidAndChatId(uid, chatId);\n        if (chatList == null || chatList.getEnable() == 0) {\n            throw new BusinessException(ResponseEnum.LONG_CONTENT_CHAT_ID_ERROR);\n        }\n        // Logical deletion of chatFileReq (unbind file from chatID)\n        if (StringUtils.isNotBlank(linkIdString)) {\n            ChatFileUser chatFileUser = chatEnhanceService.findById(Long.valueOf(linkIdString), uid);\n            if (chatFileUser == null || chatFileUser.getFileId() == null) {\n                throw new BusinessException(ResponseEnum.FILE_NOT_PROCESS);\n            }\n            fileId = chatFileUser.getFileId();\n        }\n        chatEnhanceService.delete(fileId, chatId, uid);\n\n        if (StrUtil.isNotEmpty(longFileDto.getParamName())) {\n            List<BotChatFileParam> oneByChatIdAndNameList = chatDataService.findAllBotChatFileParamByChatIdAndNameAndIsDelete(chatId, longFileDto.getParamName(), 0);","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/controller/chat/ChatEnhanceController.java#L93-L129","documentation":"DATA_NOT_FOUND is thrown in unbindFile when chatListDataService.findChatTreeIndexByChatIdOrderById(chatId) returns an empty list, meaning no chat tree index rows exist for the given chatId. The controller uses this index to resolve the latest child chatId; without any rows it cannot proceed and reports the chat as not found.","triggerScenarios":"Calling unbind-file with a chatId that has no ChatTreeIndex rows — typically a nonexistent chatId, a chatId belonging to a different environment/database, or a chat whose tree index was already deleted.","commonSituations":"Client caching an old chatId after the chat was deleted; using the parent/summary chat id instead of the child id in flows where the index was never created; pointing a test client at a fresh database.","solutions":["Verify the chatId exists by listing chats for the user before calling unbind","Refresh the chatId from the chat list API (stale/deleted chats return this error)","Check you are hitting the correct environment/database for that chatId","Confirm the chat tree index was created (chat went through the long-content flow)"],"exampleFix":"// before\nunbindFile({ chatId: 999999, fileId: \"f1\" }) // chat never created\n// after\nconst chats = await listChats();\nconst valid = chats.find(c => c.chatId === 999999);\nif (valid) await unbindFile({ chatId: 999999, fileId: \"f1\" });","handlingStrategy":"validation","validationCode":"const chats = await listChats(uid); if (!chats.some(c => c.chatId === chatId)) throw new Error('chatId does not exist');","typeGuard":null,"tryCatchPattern":"try { await unbindFile(dto); } catch (e) { if (e.code === 'DATA_NOT_FOUND') { await refreshChatList(); } else throw e; }","preventionTips":["Refresh chat ids from the server instead of caching them indefinitely","Confirm the chat went through the long-content flow so the tree index exists","Use the same environment/database as where the chat was created","Handle deleted chats by re-listing before mutations"],"tags":["not-found","chat","data-lookup"],"backgroundTag":"entity-not-found","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}