{"record":{"id":"cda3bff0ebdf843a","repo":"alibaba/spring-ai-alibaba","slug":"error-processing-template-templatename","errorCode":null,"errorMessage":"Error processing template: ${templateName}","messagePattern":"Error processing 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/agent/AgentProjectGenerator.java","lineNumber":115,"sourceCode":"\t}\n\n\tprivate void renderAndWriteTemplates(List<String> templateNames, List<Map<String, Object>> models, Path projectRoot,\n\t\t\tProjectDescription projectDescription) {\n\t\tPath fileRoot = createDirectory(projectRoot, projectDescription);\n\n\t\tfor (int i = 0; i < templateNames.size(); i++) {\n\t\t\tString templateName = templateNames.get(i);\n\t\t\tMap<String, Object> model = models.get(i);\n\t\t\tPath filePath = fileRoot.resolve(templateName);\n\n\t\t\ttry {\n\t\t\t\tString template = templateRenderer.render(templateName, model);\n\n\t\t\t\t// 覆盖写文件（自动创建/替换文件）\n\t\t\t\tFiles.writeString(filePath, template, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);\n\t\t\t}\n\t\t\tcatch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"Error processing template: \" + templateName, e);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate Path createDirectory(Path projectRoot, ProjectDescription projectDescription) {\n\t\tStringBuilder pathBuilder = new StringBuilder(\"src/main/\").append(projectDescription.getLanguage().id());\n\t\tString packagePath = projectDescription.getPackageName().replace('.', '/');\n\t\tpathBuilder.append(\"/\").append(packagePath).append(\"/graph/\");\n\t\ttry {\n\t\t\treturn Files.createDirectories(projectRoot.resolve(pathBuilder.toString()));\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new RuntimeException(\"Got error when creating files\", e);\n\t\t}\n\t}\n\n\tprivate CodeSections collectSections(Agent agent, RenderContext ctx) {\n\t\t// 递归先处理子 agent，收集子 varNames","sourceCodeStart":97,"sourceCodeEnd":133,"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/agent/AgentProjectGenerator.java#L97-L133","documentation":"AgentProjectGenerator.renderAndWriteTemplates() wraps IOException from rendering a template or writing the output file in a RuntimeException with this message. It indicates the template engine failed or the target file could not be written during project generation. The original IOException is chained as the cause.","triggerScenarios":"During generate(), templateRenderer.render(templateName, model) or Files.writeString(filePath, ...) throws IOException for one of the project's templates.","commonSituations":"Missing template resource in the packaged jar (build/packaging issue); disk full or read-only target directory; invalid characters in the project name producing an invalid file path; permission problems on the output directory.","solutions":["Inspect the chained cause (getCause()) for the real IOException — path, permission, or template resolution","Verify the output project directory exists, is writable, and has free disk space","Confirm all template resources ship in the jar (rebuild/repackage the module)","Check the project/package name for characters invalid in file paths"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"Path out = Paths.get(outputDir);\nif (!Files.isWritable(out) || out.toFile().getUsableSpace() < 10_000_000) {\n    throw new IllegalStateException(\"output directory not writable or low on disk\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    generator.generate(description);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Error processing template\")) {\n        log.error(\"Template {} failed: {}\", e.getMessage(), e.getCause());\n    }\n}","preventionTips":["Always inspect getCause() — the real IOException is chained","Pre-flight check output directory permissions and free space","Rebuild the module if templates appear missing from the jar","Validate project/package names contain only path-safe characters"],"tags":["io","template","file-write"],"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"}