iflytek/astron-agent · error · BusinessException
8519
8519
Error message
database.template.generate.failed
What it means
Thrown when DatabaseService fails to generate an import/export Excel template for a table using EasyExcel. Code 8519, message 'database.template.generate.failed'. The catch-all wraps any exception during workbook writing (head building, sheet creation, response streaming).
Solutions
- Check log 'Template generation failed, tbId=...' for the root-cause stack trace.
- Ensure no filter/interceptor wrote to or committed the response before the template is streamed.
- Retry the download; if broken pipe, it is a client-side cancellation, not a server bug.
- If OOM, reduce column count or raise heap; verify EasyExcel/POI versions match.
Example fix
// before
response.setContentType("application/octet-stream"); // wrong/absent headers can break stream
EasyExcel.write(out).head(head).sheet("模版").doWrite(new ArrayList<>());
// after
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment;filename=template.xlsx");
EasyExcel.write(response.getOutputStream()).head(head).sheet("模版").doWrite(new ArrayList<>()); Defensive patterns
Strategy: try-catch
Try / catch
try {
templateApi.downloadTemplate(tbId);
} catch (BusinessException ex) {
if ("database.template.generate.failed".equals(ex.getMessage())) {
log.error("template generation failed; retry download", ex);
}
throw ex;
} Prevention
- Don't cancel the download mid-stream; broken pipes surface as this error
- Ensure no filter writes to the response before the template stream
- Keep EasyExcel/POI versions compatible
When it happens
Trigger: Calling the template-download endpoint for a tbId when EasyExcel .doWrite fails: HttpServletResponse already committed, broken client connection mid-write, too many/odd field names for headers, or memory pressure building the head list.
Common situations: User cancels download causing broken pipe; response output stream closed by an earlier filter; huge number of columns causing OOM; EasyExcel version incompatibility with POI.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- 8528
- Header mismatch! Expected headers: , Actual headers:
- No field information found, please check if the data is…
- No valid data in file, please check if excel data is…
- RESPONSE_FAILED
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/732173682ba3a425.
Report an issue: GitHub.
Appendix: source
Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java:832
List<List<String>> head = new ArrayList<>();
for (DbTableField field : fields) {
// The header is the field name
if (Arrays.asList(SYSTEM_FIELDS).contains(field.getName())) {
continue;
}
head.add(Collections.singletonList(field.getName()));
}
// Generate a file stream using EasyExcel, writing only the header row
EasyExcel.write(response.getOutputStream())
.head(head)
.sheet("模版")
.doWrite(new ArrayList<>());
} catch (Exception ex) {
log.error("Template generation failed, tbId={}", tbId, ex);
throw new BusinessException(ResponseEnum.DATABASE_TEMPLATE_GENERATE_FAILED);
}
}
public Page<JSONObject> selectTableData(DbTableSelectDataDto dto) {
dataPermissionCheckTool.checkTbBelong(dto.getTbId());
try {
Page<JSONObject> page = new Page<>(dto.getPageNum(), dto.getPageSize());
page.setSize(Math.min(page.getSize(), MAX_PAGE_SIZE));
DbTable dbTable = dbTableMapper.selectById(dto.getTbId());
DbInfo dbInfo = dbInfoMapper.selectById(dbTable.getDbId());
String table = dialect.quoteIdent(dbTable.getName());
long limit = page.getSize();
long offset = (page.getCurrent() - 1) * page.getSize();
if (limit < 0 || offset < 0)
throw new IllegalArgumentException("Bad paging");View on GitHub (pinned to 5e758547a8)