alibaba/spring-ai-alibaba · error · RuntimeException
Got error when creating files
Error message
Got error when creating files
What it means
ContributorFileUtil.createDirectory creates <projectRoot>/<packagePath>/graph/ for generated source files and wraps any failure (IOException, security, invalid path) in RuntimeException("Got error when creating files") with the cause attached.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/utils/ContributorFileUtil.java:70
Path resourceFile = projectRoot.resolve("src/main/resources").resolve(fileName);
try {
Files.copy(inputStream, resourceFile);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public static Path createDirectory(Path projectRoot, ProjectDescription projectDescription) {
StringBuilder pathBuilder = new StringBuilder("src/main/").append(projectDescription.getLanguage().id());
String packagePath = projectDescription.getPackageName().replace('.', '/');
pathBuilder.append("/").append(packagePath).append("/graph/");
Path fileRoot;
try {
fileRoot = Files.createDirectories(projectRoot.resolve(pathBuilder.toString()));
}
catch (Exception e) {
throw new RuntimeException("Got error when creating files", e);
}
return fileRoot;
}
}
View on GitHub (pinned to f82da0b50f)
Solutions
- Check the cause (e.getCause()) to identify the underlying filesystem error
- Ensure projectRoot exists, is a writable directory, and the process user has write permission
- Sanitize packagePath of illegal filesystem characters before generation
- Verify disk space and path length limits
Example fix
// before
Path root = Files.createDirectories(Path.of("/ro-mount/gen"));
// after
Path root = Files.createDirectories(Path.of("/home/ci/writable/gen")); Defensive patterns
Strategy: try-catch
Validate before calling
Path target = projectRoot.resolve(packagePath + "/graph"); if (!Files.isDirectory(projectRoot) || !Files.isWritable(projectRoot)) { throw new IllegalStateException("Project root is not a writable directory: " + projectRoot); } Type guard
null
Try / catch
try { Path dir = ContributorFileUtil.createDirectory(projectRoot, packagePath); } catch (RuntimeException e) { log.error("Directory creation failed", e.getCause()); } Prevention
- Check write permissions on the output root before generation
- Sanitize package names used as path segments
- Run generators as a user with access to the target directory
- Monitor disk space in CI environments
When it happens
Trigger: Files.createDirectories fails — parent projectRoot doesn't exist or is a file, insufficient filesystem permissions, invalid characters in packagePath, or disk full.
Common situations: Generating into a read-only directory (CI containers); project root path typo; package path containing illegal characters derived from names; running as a user without write access to the target.
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
- Got error when creating files
- 搜索请求执行失败
- 批量索引失败
- Failed to create temp directory for converter
- SKILL.md not found at: {}
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/cb29a1030226c718.
Report an issue: GitHub.