{"record":{"id":"839569bc55eab5fb","repo":"iflytek/astron-agent","slug":"8521-database-import-failed","errorCode":"8521","errorMessage":"database.import.failed","messagePattern":"database\\.import\\.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":946,"sourceCode":"                                UserInfoManagerHandler.getUserId(),\n                                SpaceInfoUtil.getSpaceId(),\n                                dbInfo.getDbId(),\n                                DBOperateEnum.INSERT.getCode(),\n                                execDev);\n                    });\n\n            // 3) Summary\n            if (!summary.errors.isEmpty()) {\n                // Record the first 10 failed examples\n                StringBuilder sb = new StringBuilder();\n                sb.append(\"导入部分失败：success=\")\n                        .append(summary.success)\n                        .append(\", failed=\")\n                        .append(summary.failed)\n                        .append(\". 失败样例：\");\n                summary.errors.stream().limit(10).forEach(err -> sb.append(\"\\n#\").append(err.index).append(\" : \").append(err.message));\n                log.warn(\"importTableData partial failures: {}\", sb);\n                throw new BusinessException(ResponseEnum.DATABASE_IMPORT_FAILED);\n            }\n        } catch (Exception ex) {\n            log.error(\"import data failed, tbId={}, execDev={}, fileName={}\", tbId, execDev, file.getOriginalFilename(), ex);\n            throw new BusinessException(ResponseEnum.DATABASE_IMPORT_FAILED);\n        }\n    }\n\n    @Transactional\n    public void copyTable(Long tbId) {\n        try {\n            DbTable dbTable = dbTableMapper.selectById(tbId);\n            // Unify and standardize the copy names, and avoid illegal characters\n            String tableName = NamePolicy.copyName(dbTable.getName());\n\n            // build DDL CREATE TABLE new AS SELECT * FROM old\n            DbTableDto dbTableDto = new DbTableDto();\n            dbTableDto.setName(tableName);\n            String ddl = buildDDL(dbTableDto, DBOperateEnum.COPY.getCode(), dbTable.getName());","sourceCodeStart":928,"sourceCodeEnd":964,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java#L928-L964","documentation":"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'.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Read the WARN log 'importTableData partial failures' — it lists up to 10 failing row indexes with reasons.","Fix the flagged rows in the source file (types, required fields, unknown columns) and re-upload.","Ensure the file matches the generated template exactly (headers unchanged, correct format).","If the whole import threw, check 'import data failed' ERROR log for parse or DB root cause."],"exampleFix":"// before: import file row 3 has no value for required 'name'\n// after: validate file against template before upload\nrows.forEach(r -> {\n    if (r.get(\"name\") == null || r.get(\"name\").toString().isBlank()) {\n        throw new IllegalArgumentException(\"row missing required 'name'\");\n    }\n});\nimportService.importTableData(tbId, execDev, file);","handlingStrategy":"validation","validationCode":"for (int i = 0; i < rows.size(); i++) {\n    Map<String,Object> row = rows.get(i);\n    for (String k : row.keySet()) if (!fieldNames.contains(k)) throw new IllegalArgumentException(\"row \" + i + \" illegal field \" + k);\n    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());\n}","typeGuard":null,"tryCatchPattern":"try {\n    importService.importTableData(tbId, execDev, file);\n} catch (BusinessException ex) {\n    if (\"database.import.failed\".equals(ex.getMessage())) {\n        log.warn(\"partial import failures; see server WARN log for per-row errors and fix the file\");\n    }\n    throw ex;\n}","preventionTips":["Always import using the generated template without renaming headers","Pre-validate rows for required fields and types before upload","Use .xlsx format, unencrypted files"],"tags":["import","excel","validation"],"backgroundTag":"schema-validation-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"}