{"record":{"id":"84d2be8037ddd9f1","repo":"alibaba/spring-ai-alibaba","slug":"got-error-when-writing-template-templatename","errorCode":null,"errorMessage":"Got error when writing template ${templateName}","messagePattern":"Got error when writing template (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"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","lineNumber":293,"sourceCode":"\t\t\tString template;\n\t\t\ttry {\n\t\t\t\ttemplate = templateRenderer.render(templateName, models.get(i));\n\t\t\t}\n\t\t\tcatch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"Got error when rendering template\" + templateName, e);\n\t\t\t}\n\t\t\tPath file;\n\t\t\ttry {\n\t\t\t\tfile = Files.createFile(fileRoot.resolve(templateName));\n\t\t\t}\n\t\t\tcatch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"Got error when creating file\", e);\n\t\t\t}\n\t\t\ttry (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(file))) {\n\t\t\t\twriter.print(template);\n\t\t\t}\n\t\t\tcatch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"Got error when writing template \" + templateName, e);\n\t\t\t}\n\t\t}\n\t}\n\n}\n","sourceCodeStart":275,"sourceCodeEnd":299,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/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#L275-L299","documentation":"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.","triggerScenarios":"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.","commonSituations":"Disk full on the host or container; antivirus/indexer locking the file on Windows; NFS/network mount transient failure.","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."],"exampleFix":"// before\nthrow new RuntimeException(\"Got error when writing template \" + templateName, e);\n// after\nthrow new RuntimeException(\"Got error when writing template \" + templateName + \": \" + e.getMessage(), e); // plus verify disk space and file locks","handlingStrategy":"retry","validationCode":"Files.getUsableSpace(fileRoot) > templateBudgetBytes && Files.isWritable(fileRoot)","typeGuard":null,"tryCatchPattern":"try { generator.generate(spec); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Got error when writing template\")) { /* check disk space / locks, then retry */ } throw e; }","preventionTips":["Monitor free disk space on the generation output volume","Exclude output directories from antivirus/indexers","Generate to local disk rather than network mounts"],"tags":["file-io","disk","code-generation"],"backgroundTag":"file-write-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}