{"record":{"id":"256a68a87ac54978","repo":"iflytek/astron-agent","slug":"8515-database-table-delete-failed","errorCode":"8515","errorMessage":"database.table.delete.failed","messagePattern":"database\\.table\\.delete\\.failed","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java","lineNumber":665,"sourceCode":"            dbTableDto.setName(dbTable.getName());\n            String ddl = buildDDL(dbTableDto, DBOperateEnum.DELETE.getCode(), null);\n            // Delete from core system\n            for (String stmt : safeSplitStatements(ddl)) {\n                SqlRenderer.denyMultiStmtOrComment(stmt); // At this point each statement does not contain semicolon\n                coreSystemService.execDDL(stmt, UserInfoManagerHandler.getUserId(), SpaceInfoUtil.getSpaceId(), dbInfo.getDbId());\n            }\n            dbTableMapper.update(new UpdateWrapper<DbTable>().lambda()\n                    .eq(DbTable::getId, tbId)\n                    .set(DbTable::getDeleted, true));\n            // Delete table fields\n            dbTableFieldMapper.delete(new UpdateWrapper<DbTableField>().lambda()\n                    .eq(DbTableField::getTbId, tbId));\n        } catch (BusinessException ex) {\n            log.error(\"Failed to delete table, tbId={}\", tbId);\n            throw ex;\n        } catch (Exception ex) {\n            log.error(\"Failed to delete table, tbId={}\", tbId, ex);\n            throw new BusinessException(ResponseEnum.DATABASE_TABLE_DELETE_FAILED);\n        }\n    }\n\n    public void operateTableData(DbTableOperateDto dbTableOperateDto) {\n        dataPermissionCheckTool.checkTbBelong(dbTableOperateDto.getTbId());\n        try {\n            DbTable dbTable = dbTableMapper.selectById(dbTableOperateDto.getTbId());\n            List<DbTableField> fields = dbTableFieldMapper.selectList(new QueryWrapper<DbTableField>().lambda()\n                    .eq(DbTableField::getTbId, dbTable.getId()));\n            DbInfo dbInfo = dbInfoMapper.selectById(dbTable.getDbId());\n\n            // Validate and execute one by one (can be batched to improve availability)\n            final int BATCH = 100; // Adjustable\n            List<DbTableDataDto> rows = dbTableOperateDto.getData();\n            for (int i = 0; i < rows.size(); i++) {\n                DbTableDataDto data = rows.get(i);\n                validateParams(data.getTableData(), fields, data.getOperateType());\n","sourceCodeStart":647,"sourceCodeEnd":683,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java#L647-L683","documentation":"Thrown by DatabaseService.deleteTable when any unexpected exception occurs while deleting a table record and its field rows (the generic catch-all after BusinessException is rethrown). Code 8515, message 'database.table.delete.failed'. It wraps root causes like SQL errors, mapper failures, or constraint violations during the delete transaction.","triggerScenarios":"Calling deleteTable(tbId) when the underlying DELETE via dbTableFieldMapper/dbTable mapper fails — e.g. DB connection failure, SQL syntax error, foreign-key constraint, or the row was concurrently deleted. BusinessException from permission checks is rethrown unchanged, so this error only appears for non-business exceptions.","commonSituations":"Database unreachable or credentials rotated; table row locked by a concurrent transaction; schema drift between the entity mapping and actual DB schema; disk full on the DB host.","solutions":["Check the server log for 'Failed to delete table, tbId=...' to find the root-cause stack trace from the wrapped exception.","Verify database connectivity and credentials (datasource health, connection pool exhaustion).","Confirm the tbId exists and is not locked by a concurrent transaction; retry after the lock clears.","Check for foreign-key constraints referencing the table rows that block the delete.","Re-run the delete after fixing the root cause; if permission-related, a different BusinessException is raised instead."],"exampleFix":"// before: only generic handling\ntry {\n    removeTable(tbId);\n} catch (Exception ex) {\n    throw new BusinessException(ResponseEnum.DATABASE_TABLE_DELETE_FAILED);\n}\n// after: distinguish and surface root cause\ntry {\n    removeTable(tbId);\n} catch (BusinessException ex) {\n    throw ex;\n} catch (DuplicateKeyException | DataIntegrityViolationException ex) {\n    log.error(\"Table rows still referenced, tbId={}\", tbId, ex);\n    throw new BusinessException(ResponseEnum.DATABASE_TABLE_DELETE_FAILED);\n}","handlingStrategy":"try-catch","validationCode":"Long count = dbTableMapper.selectCount(new LambdaQueryWrapper<DbTable>().eq(DbTable::getTbId, tbId));\nif (count == 0) throw new IllegalStateException(\"table does not exist: \" + tbId);","typeGuard":null,"tryCatchPattern":"try {\n    databaseService.deleteTable(tbId);\n} catch (BusinessException ex) {\n    if (\"database.table.delete.failed\".equals(ex.getMessage())) {\n        log.error(\"delete failed for tbId={}, root cause in server log\", tbId, ex);\n    }\n    throw ex;\n}","preventionTips":["Check DB connectivity/health before batch delete operations","Confirm tbId exists and no dependent rows reference it","Retry transient failures with backoff"],"tags":["database","delete","data-integrity"],"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-19T12:17:13.211Z"}