{"record":{"id":"944aad5eb47116d3","repo":"flipped-aurora/gin-vue-admin","slug":"filpath-s-944aad","errorCode":null,"errorMessage":"[filpath:%s]非法模版文件!","messagePattern":"\\[filpath:(.+?)\\]非法模版文件!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_package.go","lineNumber":346,"sourceCode":"\t\t\t\tif !secondDirs[j].IsDir() {\n\t\t\t\t\text := filepath.Ext(secondDirs[j].Name())\n\t\t\t\t\tif ext != \".tpl\" {\n\t\t\t\t\t\treturn nil, nil, nil, errors.Errorf(\"[filpath:%s]非法模版后缀!\", three)\n\t\t\t\t\t}\n\t\t\t\t\tname := strings.TrimSuffix(secondDirs[j].Name(), ext)\n\t\t\t\t\tif name == \"main.go\" || name == \"plugin.go\" {\n\t\t\t\t\t\tpluginInitialize := &ast.PluginInitializeV2{\n\t\t\t\t\t\t\tType:        ast.TypePluginInitializeV2,\n\t\t\t\t\t\t\tPath:        filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, \"plugin\", entity.PackageName, name),\n\t\t\t\t\t\t\tPluginPath:  filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, \"plugin\", \"register.go\"),\n\t\t\t\t\t\t\tImportPath:  fmt.Sprintf(`\"%s/plugin/%s\"`, global.GVA_CONFIG.AutoCode.Module, entity.PackageName),\n\t\t\t\t\t\t\tPackageName: entity.PackageName,\n\t\t\t\t\t\t}\n\t\t\t\t\t\tasts[pluginInitialize.PluginPath+\"=>\"+pluginInitialize.Type.String()] = pluginInitialize\n\t\t\t\t\t\tcreates[three] = pluginInitialize.Path\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\treturn nil, nil, nil, errors.Errorf(\"[filpath:%s]非法模版文件!\", three)\n\t\t\t\t}\n\t\t\t\tswitch secondDirs[j].Name() {\n\t\t\t\tcase \"api\", \"router\", \"service\":\n\t\t\t\t\tvar threeDirs []os.DirEntry\n\t\t\t\t\tthreeDirs, err = os.ReadDir(three)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, nil, nil, errors.Wrapf(err, \"读取模版文件夹[%s]失败!\", three)\n\t\t\t\t\t}\n\t\t\t\t\tfor k := 0; k < len(threeDirs); k++ {\n\t\t\t\t\t\tif threeDirs[k].Name() == \".DS_Store\" {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfour := filepath.Join(three, threeDirs[k].Name())\n\t\t\t\t\t\tif threeDirs[k].IsDir() {\n\t\t\t\t\t\t\treturn nil, nil, nil, errors.Errorf(\"[filpath:%s]非法模版文件夹!\", four)\n\t\t\t\t\t\t}\n\t\t\t\t\t\text := filepath.Ext(four)\n\t\t\t\t\t\tif ext != \".tpl\" {","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_package.go#L328-L364","documentation":"A .tpl file directly under <templateDir>/server whose stem is neither \"main.go\" nor \"plugin.go\" cannot be classified by the generator, so templates() returns errors.Errorf(\"[filpath:%s]非法模版文件!\"). Only main.go.tpl / plugin.go.tpl are recognized top-level file templates; everything else must live inside api/router/service subfolders.","triggerScenarios":"Adding a custom .tpl file (e.g. config.tpl, xxx.go.tpl) directly in the server/ template level instead of inside api/, router/, service/, gen/, config/, initialize/, plugin/ or response/; renaming main.go.tpl to something else.","commonSituations":"Users extending templates by dropping new .tpl files at the wrong level; upgrading templates and leaving old files around; typos like Main.go.tpl or plugin.tpl at server/ level.","solutions":["Move the reported .tpl file into the appropriate subfolder (api/, router/, service/, etc.) where arbitrary .tpl names are accepted.","If it is the plugin entry template, keep the exact names main.go.tpl or plugin.go.tpl.","Delete leftover/obsolete .tpl files at the server/ root level.","Re-check after moving that the filename still contains api/enter/router/service keywords if it lives under api|router|service."],"exampleFix":"// before\nresource/package/server/utils.go.tpl\n// after\nmv resource/package/server/utils.go.tpl resource/package/server/service/  # or delete if unused","handlingStrategy":"validation","validationCode":"allowed := map[string]bool{\"main.go\": true, \"plugin.go\": true}\nentries, _ := os.ReadDir(filepath.Join(templateDir, \"server\"))\nfor _, e := range entries {\n    if e.IsDir() || filepath.Ext(e.Name()) != \".tpl\" {\n        continue\n    }\n    stem := strings.TrimSuffix(e.Name(), \".tpl\")\n    if !allowed[stem] {\n        return fmt.Errorf(\"server 层仅允许 main.go.tpl / plugin.go.tpl，发现 %s\", e.Name())\n    }\n}","typeGuard":"func isServerRootTpl(name string) bool {\n    stem := strings.TrimSuffix(name, \".tpl\")\n    return stem == \"main.go\" || stem == \"plugin.go\"\n}","tryCatchPattern":"if err := generate(); err != nil && strings.Contains(err.Error(), \"非法模版文件\") {\n    return fmt.Errorf(\"server 层存在无法识别的 .tpl 文件，移入 api/router/service 等子目录或删除: %w\", err)\n}","preventionTips":["Only main.go.tpl and plugin.go.tpl may sit at the server/ template root","Place custom templates under api/router/service/gen/config/initialize/plugin/response subfolders","Review custom template additions against the upstream layout before generating","Remove leftover .tpl files after template upgrades"],"tags":["codegen","go","validation","templates"],"backgroundTag":"invalid-template-file","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}