alibaba/spring-ai-alibaba · error · RuntimeException

Got error when creating files

Error message

Got error when creating files

What it means

AgentProjectGenerator.createDirectory() wraps any exception from Files.createDirectories() in a RuntimeException with this message. It occurs while creating src/main/<language>/<packagePath>/graph/ for the generated project. The underlying exception (e.g. FileSystemException, AccessDeniedException) is chained as the cause.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/service/generator/agent/AgentProjectGenerator.java:128

				// 覆盖写文件(自动创建/替换文件)
				Files.writeString(filePath, template, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
			}
			catch (IOException e) {
				throw new RuntimeException("Error processing template: " + templateName, e);
			}
		}
	}

	private 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/");
		try {
			return Files.createDirectories(projectRoot.resolve(pathBuilder.toString()));
		}
		catch (Exception e) {
			throw new RuntimeException("Got error when creating files", e);
		}
	}

	private CodeSections collectSections(Agent agent, RenderContext ctx) {
		// 递归先处理子 agent,收集子 varNames
		List<String> childVars = new ArrayList<>();
		List<CodeSections> childSections = new ArrayList<>();
		if (agent.getSubAgents() != null) {
			for (Agent sub : agent.getSubAgents()) {
				CodeSections cs = collectSections(sub, ctx);
				childSections.add(cs);
				childVars.add(cs.getVarName());
			}
		}

		// 当前节点由 Provider 渲染
		AgentTypeProvider provider = providerRegistry.get(agent.getAgentClass());
		AgentShell shell = AgentShell.of(agent.getAgentClass(), agent.getName(), agent.getDescription(),

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Check the chained cause for the exact filesystem error and path
  2. Ensure the target project root is writable by the process user (chmod/chown)
  3. Remove any conflicting file at the target path
  4. Verify the packageName contains only valid Java package characters

Example fix

null
Defensive patterns

Strategy: try-catch

Validate before calling

if (!Files.isDirectory(projectRoot) || !Files.isWritable(projectRoot)) {
    throw new IllegalStateException("project root must be a writable directory");
}

Try / catch

try {
    generator.generate(description);
} catch (RuntimeException e) {
    if ("Got error when creating files".equals(e.getMessage())) {
        log.error("Directory creation failed: {}", e.getCause());
    }
}

Prevention

When it happens

Trigger: createDirectory() (called via fileRoot) resolves a path built from the language id and package name and Files.createDirectories fails — unwritable parent, permission denied, or a path conflict (a file exists where a directory is needed).

Common situations: Running the generator in a read-only workspace or container; package name containing invalid path characters; leftover file at the target path from a previous run; running as a user without write permissions.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/11da1233001655f1. Report an issue: GitHub.