{"record":{"id":"8fc5facc0f044740","repo":"flipped-aurora/gin-vue-admin","slug":"filpath-s-8fc5fa","errorCode":null,"errorMessage":"[filpath:%s]读取模版文件失败!","messagePattern":"\\[filpath:(.+?)\\]读取模版文件失败!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_template.go","lineNumber":164,"sourceCode":"\t\tbuilder.WriteString(\"```\" + suffix + \"\\n\\n\")\n\t\tbuilder.WriteString(writer.String())\n\t\tbuilder.WriteString(\"\\n\\n```\")\n\t\tpreview[key] = builder.String()\n\t}\n\treturn preview, nil\n}\n\nfunc (s *autoCodeTemplate) generate(ctx context.Context, info request.AutoCode, entity model.SysAutoCodePackage) (map[string]strings.Builder, map[string]string, map[string]utilsAst.Ast, error) {\n\ttemplates, asts, _, err := AutoCodePackage.templates(ctx, entity, info, false)\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\tcode := make(map[string]strings.Builder)\n\tfor key, create := range templates {\n\t\tvar files *template.Template\n\t\tfiles, err = template.New(filepath.Base(key)).Funcs(autocode.GetTemplateFuncMap()).ParseFiles(key)\n\t\tif err != nil {\n\t\t\treturn nil, nil, nil, errors.Wrapf(err, \"[filpath:%s]读取模版文件失败!\", key)\n\t\t}\n\t\tvar builder strings.Builder\n\t\terr = files.Execute(&builder, info)\n\t\tif err != nil {\n\t\t\treturn nil, nil, nil, errors.Wrapf(err, \"[filpath:%s]生成文件失败!\", create)\n\t\t}\n\t\tcode[create] = builder\n\t} // 生成文件\n\tinjectedCode, injections, err := renderAutoCodeInjections(info, asts)\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\tfor key, builder := range injectedCode {\n\t\tcode[key] = builder\n\t}\n\t// 注入代码\n\treturn code, templates, injections, nil\n}","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_template.go#L146-L182","documentation":"During generate (used by Create and Preview), each template file is parsed with text/template ParseFiles; a parse/read failure is wrapped as '[filpath:%s]读取模版文件失败!'. It means the .tpl file at `key` is missing, unreadable, or has invalid template syntax, so template generation aborts.","triggerScenarios":"generate() iterating the templates map when: the template path does not exist on disk (AutoCode.Root/Server/Web config wrong), file permissions deny read, or the .tpl content has malformed {{ }} actions that text/template cannot parse.","commonSituations":"Upgrading gin-vue-admin but resource/template directories out of sync; running the server from a working directory where GVA_CONFIG.AutoCode.Root is relative and wrong; custom-edited .tpl with unbalanced {{if}}/{{end}}; missing template files in Docker image due to incomplete COPY.","solutions":["Check the filepath printed in the error exists and is readable (ls -l <path>); restore the missing .tpl from the official server/resource/template directory.","Validate the template syntax — unbalanced {{if}}/{{range}}/{{end}} or bad pipeline causes ParseFiles to fail; revert recent custom edits to that .tpl.","Verify config.yaml autoCode section (root/server/web paths) points to the directory that actually contains the template resources."],"exampleFix":"// bad template\n{{ if .HasDataSource }}\n  ...missing {{ end }}\n// fixed\n{{ if .HasDataSource }}\n  ...\n{{ end }}","handlingStrategy":"validation","validationCode":"tplPath := key\nif _, err := os.Stat(tplPath); err != nil {\n  return fmt.Errorf(\"template missing: %s\", tplPath)\n}\nif _, err := template.New(filepath.Base(tplPath)).ParseFiles(tplPath); err != nil {\n  return fmt.Errorf(\"template syntax invalid: %s: %v\", tplPath, err)\n}","typeGuard":null,"tryCatchPattern":"result, err := svc.generate(...)\nif err != nil {\n  if strings.Contains(err.Error(), \"读取模版文件失败\") {\n    log.Printf(\"restore template from server/resource/template: %v\", err)\n  }\n  return err\n}","preventionTips":["Never hand-edit .tpl files without validating with a quick ParseFiles smoke test.","Ensure Docker/CI images COPY the full server/resource/template tree.","Pin AutoCode root/server paths in config.yaml to absolute paths in deployments."],"tags":["template","codegen","file-io","text-template"],"backgroundTag":"template-parse-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}