alibaba/spring-ai-alibaba · error · RuntimeException
Got error when writing template ${templateName}
Error message
Got error when writing template ${templateName} What it means
renderAndWriteTemplates writes the rendered template with PrintWriter.print inside try-with-resources; an IOException from the BufferedWriter is wrapped in a RuntimeException named 'Got error when writing template <name>'. This means rendering and file creation succeeded but persisting the content to disk failed.
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/workflow/WorkflowProjectGenerator.java:293
String template;
try {
template = templateRenderer.render(templateName, models.get(i));
}
catch (IOException e) {
throw new RuntimeException("Got error when rendering template" + templateName, e);
}
Path file;
try {
file = Files.createFile(fileRoot.resolve(templateName));
}
catch (IOException e) {
throw new RuntimeException("Got error when creating file", e);
}
try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(file))) {
writer.print(template);
}
catch (IOException e) {
throw new RuntimeException("Got error when writing template " + templateName, e);
}
}
}
}
View on GitHub (pinned to f82da0b50f)
Solutions
- Free disk space on the volume holding the output directory and retry generation.
- Check the file is not locked by another process (IDE sync, antivirus) and exclude the output dir from scanning.
- Retry generation; if on a network mount, generate to a local directory instead.
Example fix
// before
throw new RuntimeException("Got error when writing template " + templateName, e);
// after
throw new RuntimeException("Got error when writing template " + templateName + ": " + e.getMessage(), e); // plus verify disk space and file locks Defensive patterns
Strategy: retry
Validate before calling
Files.getUsableSpace(fileRoot) > templateBudgetBytes && Files.isWritable(fileRoot)
Try / catch
try { generator.generate(spec); } catch (RuntimeException e) { if (e.getMessage().startsWith("Got error when writing template")) { /* check disk space / locks, then retry */ } throw e; } Prevention
- Monitor free disk space on the generation output volume
- Exclude output directories from antivirus/indexers
- Generate to local disk rather than network mounts
When it happens
Trigger: generate() -> renderAndWriteTemplates: writer.print(template) fails on flush/close, e.g. disk full, device error, or the file was removed/locked between creation and writing.
Common situations: Disk full on the host or container; antivirus/indexer locking the file on Windows; NFS/network mount transient failure.
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 file
- Got error when rendering template${templateName}
- URL路径不能为空
- unsupported document type: ${documentType}
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/84d2be8037ddd9f1.
Report an issue: GitHub.