iflytek/astron-agent · error · BusinessException

8521

8521

Error message

database.import.failed

What it means

Thrown by DatabaseService.importTableData when importing rows from an uploaded Excel file fails, either because some rows failed validation/insert (partial failure summary logged) or the whole import threw. Code 8521, message 'database.import.failed'.

Solutions

  1. Read the WARN log 'importTableData partial failures' — it lists up to 10 failing row indexes with reasons.
  2. Fix the flagged rows in the source file (types, required fields, unknown columns) and re-upload.
  3. Ensure the file matches the generated template exactly (headers unchanged, correct format).
  4. If the whole import threw, check 'import data failed' ERROR log for parse or DB root cause.

Example fix

// before: import file row 3 has no value for required 'name'
// after: validate file against template before upload
rows.forEach(r -> {
    if (r.get("name") == null || r.get("name").toString().isBlank()) {
        throw new IllegalArgumentException("row missing required 'name'");
    }
});
importService.importTableData(tbId, execDev, file);
Defensive patterns

Strategy: validation

Validate before calling

for (int i = 0; i < rows.size(); i++) {
    Map<String,Object> row = rows.get(i);
    for (String k : row.keySet()) if (!fieldNames.contains(k)) throw new IllegalArgumentException("row " + i + " illegal field " + k);
    for (DbTableField f : fields) if (Boolean.TRUE.equals(f.getIsRequired()) && f.getDefaultValue() == null && !row.containsKey(f.getName())) throw new IllegalArgumentException("row " + i + " missing " + f.getName());
}

Try / catch

try {
    importService.importTableData(tbId, execDev, file);
} catch (BusinessException ex) {
    if ("database.import.failed".equals(ex.getMessage())) {
        log.warn("partial import failures; see server WARN log for per-row errors and fix the file");
    }
    throw ex;
}

Prevention

When it happens

Trigger: Uploading an import file where rows contain illegal fields, missing required fields, or values that fail DML — the summary collects errors and, if summary.failed > 0, this error is thrown with up to 10 sample failures logged at WARN. Also thrown for whole-flow exceptions (unreadable file, EasyExcel parse errors, DB down).

Common situations: Users upload spreadsheets with renamed headers, empty required cells, wrong data types, or files saved in unsupported formats (.xls vs .xlsx); corrupted uploads; network interruption mid-upload.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/839569bc55eab5fb. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java:946

                                UserInfoManagerHandler.getUserId(),
                                SpaceInfoUtil.getSpaceId(),
                                dbInfo.getDbId(),
                                DBOperateEnum.INSERT.getCode(),
                                execDev);
                    });

            // 3) Summary
            if (!summary.errors.isEmpty()) {
                // Record the first 10 failed examples
                StringBuilder sb = new StringBuilder();
                sb.append("导入部分失败:success=")
                        .append(summary.success)
                        .append(", failed=")
                        .append(summary.failed)
                        .append(". 失败样例:");
                summary.errors.stream().limit(10).forEach(err -> sb.append("\n#").append(err.index).append(" : ").append(err.message));
                log.warn("importTableData partial failures: {}", sb);
                throw new BusinessException(ResponseEnum.DATABASE_IMPORT_FAILED);
            }
        } catch (Exception ex) {
            log.error("import data failed, tbId={}, execDev={}, fileName={}", tbId, execDev, file.getOriginalFilename(), ex);
            throw new BusinessException(ResponseEnum.DATABASE_IMPORT_FAILED);
        }
    }

    @Transactional
    public void copyTable(Long tbId) {
        try {
            DbTable dbTable = dbTableMapper.selectById(tbId);
            // Unify and standardize the copy names, and avoid illegal characters
            String tableName = NamePolicy.copyName(dbTable.getName());

            // build DDL CREATE TABLE new AS SELECT * FROM old
            DbTableDto dbTableDto = new DbTableDto();
            dbTableDto.setName(tableName);
            String ddl = buildDDL(dbTableDto, DBOperateEnum.COPY.getCode(), dbTable.getName());

View on GitHub (pinned to 5e758547a8)