{"record":{"id":"5a33e90814baaeaf","repo":"iflytek/astron-agent","slug":"toolbox-not-exist-delete","errorCode":"TOOLBOX_NOT_EXIST_DELETE","errorMessage":"BusinessException(ResponseEnum.TOOLBOX_NOT_EXIST_DELETE)","messagePattern":"BusinessException\\(ResponseEnum\\.TOOLBOX_NOT_EXIST_DELETE\\)","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/tool/ToolBoxService.java","lineNumber":428,"sourceCode":"            try {\n                Object valueA = field.get(a);\n                Object valueB = field.get(b);\n                if (!Objects.equals(valueA, valueB)) {\n                    return false;\n                }\n            } catch (IllegalAccessException e) {\n                throw new RuntimeException(\"Failed to compare field: \" + field.getName(), e);\n            }\n        }\n\n        return true;\n    }\n\n    @Transactional\n    public Object deleteTool(Long id) {\n        ToolBox toolBox = getById(id);\n        if (toolBox == null) {\n            throw new BusinessException(ResponseEnum.TOOLBOX_NOT_EXIST_DELETE);\n        }\n        dataPermissionCheckTool.checkToolBelong(toolBox);\n        // Delete draft tools directly\n        if (toolBox.getStatus().equals(0)) {\n            toolBox.setDeleted(true);\n            toolBox.setUpdateTime(new Timestamp(System.currentTimeMillis()));\n            updateById(toolBox);\n            return ApiResult.success();\n        }\n\n        long flowListCount = flowToolRelMapper.selectCount(Wrappers.lambdaQuery(FlowToolRel.class).eq(FlowToolRel::getToolId, toolBox.getToolId()));\n        if (flowListCount > 0) {\n            throw new BusinessException(ResponseEnum.TOOLBOX_CANNOT_DELETE_RELATED_WORKFLOW);\n        }\n\n        long modelListCount = botToolRelService.count(Wrappers.lambdaQuery(BotToolRel.class).eq(BotToolRel::getToolId, toolBox.getToolId()));\n        if (modelListCount > 0) {\n            throw new BusinessException(ResponseEnum.TOOLBOX_CANNOT_DELETE_RELATED);","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/tool/ToolBoxService.java#L410-L446","documentation":"ToolBoxService.deleteTool throws TOOLBOX_NOT_EXIST_DELETE when getById(id) finds no ToolBox for the given id. Deletion is aborted before any permission check or soft-delete. The distinct code (vs TOOLBOX_NOT_EXIST) marks the failure as coming from the delete operation.","triggerScenarios":"Calling the tool delete API with a nonexistent id; deleting an already-deleted (soft-deleted, deleted=true) tool; id from a stale UI list after another user removed the tool; id belonging to a different tenant/space.","commonSituations":"Double-click delete causing second call to hit an already-deleted row; automated cleanup scripts using outdated inventories; cross-environment id reuse (dev ids used in prod).","solutions":["Confirm the tool id exists via getDetail or the tool list before deleting.","Treat this error as idempotent success if the goal is 'tool is gone' — refresh the list.","Check tenant/space context: the tool may exist under a different space.","Fix clients to remove the item from the list after a successful delete to avoid duplicate delete calls."],"exampleFix":"// before\ntoolBoxService.deleteTool(id); // throws if already deleted\n// after\ntry {\n    toolBoxService.deleteTool(id);\n} catch (BusinessException e) {\n    // treat TOOLBOX_NOT_EXIST_DELETE as already-deleted; tolerate idempotent delete\n}","handlingStrategy":"try-catch","validationCode":"boolean exists = toolBoxService.getById(id) != null;\nif (exists) { toolBoxService.deleteTool(id); }","typeGuard":null,"tryCatchPattern":"try {\n    toolBoxService.deleteTool(id);\n} catch (BusinessException e) {\n    if (\"TOOLBOX_NOT_EXIST_DELETE\".equals(e.getCode())) {\n        // already deleted; treat as idempotent success\n    }\n}","preventionTips":["Remove items from UI lists immediately after successful delete to prevent duplicate calls.","Guard against double-click on delete buttons (disable after first click).","Verify tool existence before issuing delete in scripts."],"tags":["tool-management","not-found","delete-operation"],"backgroundTag":"record-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"}