{"record":{"id":"ac0e12958cf0857c","repo":"alibaba/spring-ai-alibaba","slug":"got-error-when-rendering-template-templatename","errorCode":null,"errorMessage":"Got error when rendering template${templateName}","messagePattern":"Got error when rendering template(.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","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":280,"sourceCode":"\n\t\tStringBuilder sb = new StringBuilder();\n\t\tallImports.forEach(className -> sb.append(\"import \").append(className).append(\";\\n\"));\n\n\t\treturn sb.toString();\n\t}\n\n\tprivate void renderAndWriteTemplates(List<String> templateNames, List<Map<String, Object>> models, Path projectRoot,\n\t\t\tProjectDescription projectDescription) {\n\t\t// todo: may to standardize the code format via the IdentifierGeneratorFactory\n\t\tPath fileRoot = ContributorFileUtil.createDirectory(projectRoot, projectDescription);\n\t\tfor (int i = 0; i < templateNames.size(); i++) {\n\t\t\tString templateName = templateNames.get(i);\n\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}","sourceCodeStart":262,"sourceCodeEnd":298,"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#L262-L298","documentation":"WorkflowProjectGenerator.renderAndWriteTemplates renders each template via TemplateRenderer.render and wraps any IOException from rendering in a RuntimeException. The message omits a separator between the literal text and the template name, so the template name is concatenated directly (e.g. '...templatepom.xml'). It indicates the template resource could not be read/rendered, aborting code generation.","triggerScenarios":"generate() -> renderAndWriteTemplates: TemplateRenderer.render(templateName, models.get(i)) throws IOException for a template in templateNames, e.g. missing template resource on the classpath or unreadable template file.","commonSituations":"Template file missing from packaged resources after a partial build; wrong working directory when running the generator standalone; classpath resources not copied in an IDE run configuration.","solutions":["Rebuild the module (./mvnw -pl :spring-ai-alibaba-admin-server-start package) so template resources are on the classpath.","Verify each templateName in templateNames maps to an existing template resource.","Run the generator via the full StudioApplication, not a stripped-down main, so resource loading works."],"exampleFix":"// before\nthrow new RuntimeException(\"Got error when rendering template\" + templateName, e);\n// after\nthrow new RuntimeException(\"Got error when rendering template \" + templateName, e); // also check the template exists on the classpath","handlingStrategy":"try-catch","validationCode":"for (String name : templateNames) {\n    if (getClass().getResource(\"/templates/\" + name) == null)\n        throw new IllegalStateException(\"Missing template resource: \" + name);\n}","typeGuard":null,"tryCatchPattern":"try { generator.generate(spec); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Got error when rendering template\")) { /* rebuild/redeploy templates */ } throw e; }","preventionTips":["Run `./mvnw package` so template resources are copied into the jar","Verify template files exist in src/main/resources before running generation","Run generation from the full StudioApplication, not ad-hoc runners"],"tags":["template-rendering","io","code-generation"],"backgroundTag":"file-read-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"}