{"record":{"id":"0962f87e19e84d15","repo":"flipped-aurora/gin-vue-admin","slug":"filepath-s-0962f8","errorCode":null,"errorMessage":"[filepath:%s]读取模版文件失败!","messagePattern":"\\[filepath:(.+?)\\]读取模版文件失败!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_template.go","lineNumber":279,"sourceCode":"\t\treturn nil, err\n\t}\n\tserverStr, err := s.getTemplateStr(\"server.go\", info)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tjsStr, err := s.getTemplateStr(\"api.js\", info)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn map[string]string{\"api\": apiStr, \"server\": serverStr, \"js\": jsStr}, nil\n\n}\n\nfunc (s *autoCodeTemplate) getTemplateStr(t string, info request.AutoFunc) (string, error) {\n\ttempPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, \"resource\", \"function\", t+\".tpl\")\n\tfiles, err := template.New(filepath.Base(tempPath)).Funcs(autocode.GetTemplateFuncMap()).ParseFiles(tempPath)\n\tif err != nil {\n\t\treturn \"\", errors.Wrapf(err, \"[filepath:%s]读取模版文件失败!\", tempPath)\n\t}\n\tvar builder strings.Builder\n\terr = files.Execute(&builder, info)\n\tif err != nil {\n\t\tfmt.Println(err.Error())\n\t\treturn \"\", errors.Wrapf(err, \"[filpath:%s]生成文件失败!\", tempPath)\n\t}\n\treturn builder.String(), nil\n}\n\nfunc (s *autoCodeTemplate) addTemplateToAst(t string, info request.AutoFunc) error {\n\tif !isSafeFileName(info.HumpPackageName) {\n\t\treturn fmt.Errorf(\"文件名包含非法字符，拒绝写入\")\n\t}\n\ttPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, \"router\", info.Package, info.HumpPackageName+\".go\")\n\tfuncName := fmt.Sprintf(\"Init%sRouter\", info.StructName)\n\n\trouterStr := \"RouterWithoutAuth\"","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_template.go#L261-L297","documentation":"getTemplateStr parses the function template at <Root>/<Server>/resource/function/<t>.tpl before rendering auto-function code; a read/parse failure is wrapped as '[filepath:%s]读取模版文件失败!'. Called by GetApiAndServer and addTemplateToFile when generating auto-function (low-code function) assets.","triggerScenarios":"AutoFunc generation when: the function .tpl file does not exist under resource/function (missing resource files or wrong AutoCode.Root/Server config), file unreadable (permissions), or the .tpl has invalid template syntax for ParseFiles.","commonSituations":"Deployed binary shipped without the resource/function directory; config.yaml autoCode.root pointing to a path that differs between dev and deployment; custom function template with unbalanced {{ }} actions.","solutions":["Confirm the file <filepath> printed in the error exists (ls); restore it from server/resource/function in the repository.","Check config.yaml AutoCode.Root and AutoCode.Server values resolve to the server directory containing resource/function.","Validate the .tpl template syntax; revert recent edits with unbalanced {{if}}/{{end}} or bad pipelines."],"exampleFix":"// config.yaml before\nautoCode:\n  root: \"\"            # wrong\n// after\nautoCode:\n  root: \".\"           # resolves to server dir with resource/function","handlingStrategy":"validation","validationCode":"tempPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, \"resource\", \"function\", t+\".tpl\")\nif _, err := os.Stat(tempPath); os.IsNotExist(err) {\n  return fmt.Errorf(\"function template missing: %s\", tempPath)\n}","typeGuard":null,"tryCatchPattern":"str, err := svc.getTemplateStr(t, info)\nif err != nil && strings.Contains(err.Error(), \"读取模版文件失败\") {\n  log.Printf(\"restore .tpl under resource/function: %v\", err)\n  return err\n}","preventionTips":["Verify AutoCode.Root/AutoCode.Server in config.yaml on every deployment.","Include resource/function templates in build/packaging artifacts.","Validate custom .tpl syntax before deploying."],"tags":["template","codegen","file-io","config"],"backgroundTag":"template-file-missing","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}