elunez/eladmin · error · BadRequestException

生成失败,请手动处理已生成的文件

Error message

生成失败,请手动处理已生成的文件

What it means

GeneratorServiceImpl.generator wraps GenUtil.generatorCode in a try/catch; an IOException while writing generated templates to disk is logged and rethrown as BadRequestException('生成失败,请手动处理已生成的文件'). Because the writer may have emitted some files before failing, the message warns that partial output may exist.

Source

Thrown at eladmin-generator/src/main/java/me/zhengjie/service/impl/GeneratorServiceImpl.java:178

            }
        }
    }

    @Override
    public void save(List<ColumnInfo> columnInfos) {
        columnInfoRepository.saveAll(columnInfos);
    }

    @Override
    public void generator(GenConfig genConfig, List<ColumnInfo> columns) {
        if (genConfig.getId() == null) {
            throw new BadRequestException(CONFIG_MESSAGE);
        }
        try {
            GenUtil.generatorCode(columns, genConfig);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
            throw new BadRequestException("生成失败,请手动处理已生成的文件");
        }
    }

    @Override
    public ResponseEntity<Object> preview(GenConfig genConfig, List<ColumnInfo> columns) {
        if (genConfig.getId() == null) {
            throw new BadRequestException(CONFIG_MESSAGE);
        }
        List<Map<String, Object>> genList = GenUtil.preview(columns, genConfig);
        return new ResponseEntity<>(genList, HttpStatus.OK);
    }

    @Override
    public void download(GenConfig genConfig, List<ColumnInfo> columns, HttpServletRequest request, HttpServletResponse response) {
        if (genConfig.getId() == null) {
            throw new BadRequestException(CONFIG_MESSAGE);
        }
        try {

View on GitHub (pinned to 55fbf70595)

Solutions

  1. Check the logged IOException stack trace (log.error before the throw) to identify the exact failing path.
  2. Grant write permission (chown/chmod) to the service user for genConfig.path and its parents, or point the path to a writable directory.
  3. Free disk space / raise the container volume size, then retry.
  4. Inspect the output directory for partially generated files and delete or complete them manually, as the message advises.

Example fix

# before: generation path not writable
# gen_config.path = /opt/codegen  (owned by root, app runs as 'eladmin')

# after
sudo chown -R eladmin:eladmin /opt/codegen
# or update gen_config row to a writable path, e.g. /home/eladmin/codegen
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify the output location is writable before generating
String outDir = genConfig.getPath() + "/" + genConfig.getPackName().replace('.', '/');
File f = new File(outDir);
Files.createDirectories(f.getParentFile().toPath());
if (!f.getParentFile().canWrite()) throw new IllegalStateException("No write permission: " + outDir);

Type guard

boolean canWriteTo(String path) {
    File dir = new File(path);
    return dir.exists() ? dir.canWrite() : dir.getAbsoluteFile().getParentFile().canWrite();
}

Try / catch

try {
    generatorService.generator(config, columns);
} catch (BadRequestException e) {
    if (e.getMessage().contains("生成失败")) {
        auditOutputDirectoryForPartialFiles(genConfig); // message warns partial files exist
    }
    throw e;
}

Prevention

When it happens

Trigger: type=0 generation where the template engine cannot create/write files under the configured path (genConfig.getPath() + package dirs): no write permission, a read-only volume, disk full, or the output directory was deleted mid-run.

Common situations: Running the jar as a user without write access to /opt/app/... or the configured generation path; container with a read-only layer; disk quota exhausted; relative path resolving to an unexpected cwd.

Related errors


AI-assisted analysis of elunez/eladmin@55fbf70595 (2026-08-14). Data as JSON: /api/errors/d16034343dddc40e. Report an issue: GitHub.