{"record":{"id":"fec48474c9cd33b7","repo":"iflytek/astron-agent","slug":"bot-update-failed","errorCode":"BOT_UPDATE_FAILED","errorMessage":"BOT_UPDATE_FAILED","messagePattern":"BOT_UPDATE_FAILED","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/strategy/publish/impl/MarketPublishStrategy.java","lineNumber":219,"sourceCode":"        marketRecord.setOpenedTool(botBase.getOpenedTool());\n\n        // Market-specific fields with defaults\n        marketRecord.setShowIndex(0);\n        marketRecord.setShowOthers(0);\n        marketRecord.setHotNum(0);\n        marketRecord.setShowWeight(0);\n\n        // Status and channel management\n        marketRecord.setBotStatus(status);\n        marketRecord.setPublishChannels(channels);\n        marketRecord.setIsDelete(0);\n        marketRecord.setCreateTime(LocalDateTime.now());\n        marketRecord.setUpdateTime(LocalDateTime.now());\n\n        // Insert record\n        int insertCount = chatBotMarketMapper.insert(marketRecord);\n        if (insertCount == 0) {\n            throw new BusinessException(ResponseEnum.BOT_UPDATE_FAILED);\n        }\n\n        log.info(\"Created bot market record: botId={}, version={}, status={}, channels={}\",\n                botId, botBase.getVersion(), status, channels);\n    }\n\n    /**\n     * Sync bot data from chat_bot_base to chat_bot_market (for existing records) When re-publishing,\n     * sync all latest data to ensure consistency\n     */\n    private void syncBotDataToMarket(Integer botId, String uid, Long spaceId, Integer newStatus, String newChannels) {\n        // Query latest bot data\n        ChatBotBase botBase = chatBotBaseMapper.selectById(botId);\n        if (botBase == null) {\n            throw new BusinessException(ResponseEnum.BOT_NOT_EXISTS);\n        }\n\n        // Build update wrapper to sync all data fields","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/strategy/publish/impl/MarketPublishStrategy.java#L201-L237","documentation":"insertBotMarketRecord() throws BOT_UPDATE_FAILED when chatBotMarketMapper.insert(marketRecord) returns 0 rows affected. MyBatis-Plus insert returning 0 means the new chat_bot_market record was not persisted (constraint violation swallowed, SQL failure reported as 0 affected rows, or no row inserted).","triggerScenarios":"Inserting a chat_bot_market row whose bot_id already exists under a unique key, or a DB-level insert failure causing MyBatis to report 0 affected rows during handleBotMarketSync.","commonSituations":"Duplicate market record from a previous partial publish (unique index on bot_id/space); schema mismatch between entity fields and table columns; DB trigger or strict mode rejecting the row.","solutions":["Check for an existing chat_bot_market row for the botId first and update instead of inserting (upsert semantics)","Inspect DB constraints/unique indexes on chat_bot_market and enable SQL logging to see why the insert affected 0 rows","Verify the ChatBotMarket entity mapping (table name, columns, NOT NULL columns all populated) matches the schema","If the insert result is unreliable in your driver/DB, rely on exceptions rather than the affected-row count to detect failure"],"exampleFix":"// before\nint insertCount = chatBotMarketMapper.insert(marketRecord);\nif (insertCount == 0) throw new BusinessException(ResponseEnum.BOT_UPDATE_FAILED);\n// after\nChatBotMarket existing = chatBotMarketMapper.selectByBotId(botId);\nif (existing != null) { /* update existing row */ } else {\n    int insertCount = chatBotMarketMapper.insert(marketRecord);\n    if (insertCount == 0) throw new BusinessException(ResponseEnum.BOT_UPDATE_FAILED);\n}","handlingStrategy":"try-catch","validationCode":"ChatBotMarket existing = chatBotMarketMapper.selectByBotId(botId);\nboolean alreadyPresent = existing != null;","typeGuard":null,"tryCatchPattern":"try {\n    marketPublishStrategy.handleBotMarketSync(botId, uid, spaceId);\n} catch (BusinessException e) {\n    if (\"BOT_UPDATE_FAILED\".equals(e.getCode())) {\n        // inspect chat_bot_market constraints / duplicate rows and retry as update\n    } else throw e;\n}","preventionTips":["Prefer upsert logic: check for an existing market row before inserting","Add unique-index-aware handling for bot_id in chat_bot_market","Enable MyBatis SQL logging to diagnose 0-affected-row inserts"],"tags":["database","insert","publishing"],"backgroundTag":"database-write-failed","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"}