{"record":{"id":"a5e21a32664033c2","repo":"iflytek/astron-agent","slug":"8528-database-table-export-failed","errorCode":"8528","errorMessage":"database.table.export.failed","messagePattern":"database\\.table\\.export\\.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":1081,"sourceCode":"                    } else {\n                        line.add(val != null ? val : \"\");\n                    }\n                }\n                dataList.add(line);\n            }\n\n            response.setContentType(\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\");\n            response.setCharacterEncoding(\"utf-8\");\n            String fileName = URLEncoder.encode(dbTable.getName(), \"UTF-8\").replaceAll(\"\\\\+\", \"%20\");\n            response.setHeader(\"Content-disposition\", \"attachment;filename=\" + fileName + \".xlsx\");\n\n            EasyExcel.write(response.getOutputStream())\n                    .head(headList)\n                    .sheet(\"data\")\n                    .doWrite(dataList);\n        } catch (Exception ex) {\n            log.error(\"export data failed, params:{}\", dto, ex);\n            throw new BusinessException(ResponseEnum.DATABASE_TABLE_EXPORT_FAILED);\n        }\n    }\n\n    public List<DbTableInfoVo> getDbTableInfoList() {\n        List<DbTableInfoVo> result = new ArrayList<>();\n        dbInfoMapper.selectList(new QueryWrapper<DbInfo>().lambda()\n                .and(SpaceInfoUtil.getSpaceId() == null,\n                        wrapper -> wrapper.eq(DbInfo::getUid, UserInfoManagerHandler.getUserId())\n                                .isNull(DbInfo::getSpaceId))\n                .eq(SpaceInfoUtil.getSpaceId() != null, DbInfo::getSpaceId, SpaceInfoUtil.getSpaceId())\n                .eq(DbInfo::getDeleted, false))\n                .forEach(dbInfo -> {\n                    DbTableInfoVo dbTableInfoVo = new DbTableInfoVo();\n                    dbTableInfoVo.setLabel(dbInfo.getName());\n                    dbTableInfoVo.setValue(dbInfo.getDbId().toString());\n                    List<DbTable> dbTables = dbTableMapper.selectList(new QueryWrapper<DbTable>().lambda()\n                            .eq(DbTable::getDbId, dbInfo.getId())\n                            .eq(DbTable::getDeleted, false));","sourceCodeStart":1063,"sourceCodeEnd":1099,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java#L1063-L1099","documentation":"Thrown by DatabaseService.exportData when EasyExcel fails to write the table export workbook to the HTTP response output stream. The method wraps any exception from the EasyExcel write pipeline (head building, sheet creation, doWrite) into BusinessException(ResponseEnum.DATABASE_TABLE_EXPORT_FAILED, code 8528). It indicates the Excel export for a database table could not be delivered to the client.","triggerScenarios":"Calling the table-data export endpoint when EasyExcel.write(...).head(headList).sheet(\"data\").doWrite(dataList) throws — e.g. headList/dataList structure mismatch, IOException on response.getOutputStream() (client disconnected, response already committed), or a cell value type EasyExcel cannot serialize.","commonSituations":"Large exports that exceed memory or hit client-side connection timeouts mid-stream; response already partially written/committed before the call; incompatible data types in dataList columns; custom head list not matching data rows.","solutions":["Check the server log line 'export data failed, params:{...}' for the root exception (often an IOException from the servlet output stream).","Verify the export response has not already been committed and content-type/content-disposition headers are set before EasyExcel writes.","Confirm dataList cell values match the headList schema and contain EasyExcel-compatible types (or add converters).","For large tables, paginate or stream in batches to avoid OOM during doWrite."],"exampleFix":"// before\nEasyExcel.write(response.getOutputStream())\n    .head(headList)\n    .sheet(\"data\")\n    .doWrite(dataList);\n// after\nresponse.reset();\nresponse.setContentType(\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\");\nresponse.setCharacterEncoding(\"utf-8\");\ntry (ServletOutputStream out = response.getOutputStream()) {\n    EasyExcel.write(out)\n        .head(headList)\n        .sheet(\"data\")\n        .doWrite(() -> batchIterator); // stream batches instead of one huge list\n}","handlingStrategy":"try-catch","validationCode":"// before export\nif (dataList == null || headList == null || response.isCommitted()) {\n    throw new IllegalArgumentException(\"export requires headList/dataList and an uncommitted response\");\n}","typeGuard":"boolean isExportable(List<?> headList, List<?> dataList) {\n    return headList != null && !headList.isEmpty() && dataList != null;\n}","tryCatchPattern":"try {\n    EasyExcel.write(response.getOutputStream()).head(headList).sheet(\"data\").doWrite(dataList);\n} catch (Exception ex) {\n    log.error(\"export data failed, params:{}\", dto, ex);\n    throw new BusinessException(ResponseEnum.DATABASE_TABLE_EXPORT_FAILED);\n}","preventionTips":["Set content-type and content-disposition headers before writing and never touch the response afterwards.","Stream large datasets in batches instead of building one huge dataList.","Keep headList and dataList column counts/types aligned; add EasyExcel converters for non-trivial types.","Monitor for OOM/timeout on export endpoints and cap export size."],"tags":["excel","export","servlet","easyexcel"],"backgroundTag":"file-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"}