flipped-aurora/gin-vue-admin · error
读取模版文件夹[%s]失败!
Error message
读取模版文件夹[%s]失败!
What it means
The internal autoCodePackage.templates helper reads the top-level template directory <AutoCode.Root>/<AutoCode.Server>/resource/<entity.Template> via os.ReadDir and wraps any failure with "读取模版文件夹[%s]失败!". It means the configured template root for the selected package template does not exist or cannot be read.
Source
Thrown at server/service/system/auto_code_package.go:309
for i := 0; i < len(entries); i++ {
if entries[i].IsDir() {
if ignoreDirs[entries[i].Name()] {
continue
}
templates = append(templates, entries[i].Name())
}
}
return templates, nil
}
func (s *autoCodePackage) templates(ctx context.Context, entity model.SysAutoCodePackage, info request.AutoCode, isPackage bool) (code map[string]string, asts map[string]ast.Ast, creates map[string]string, err error) {
code = make(map[string]string)
asts = make(map[string]ast.Ast)
creates = make(map[string]string)
templateDir := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "resource", entity.Template)
templateDirs, err := os.ReadDir(templateDir)
if err != nil {
return nil, nil, nil, errors.Wrapf(err, "读取模版文件夹[%s]失败!", templateDir)
}
for i := 0; i < len(templateDirs); i++ {
second := filepath.Join(templateDir, templateDirs[i].Name())
switch templateDirs[i].Name() {
case "server":
if !info.GenerateServer && !isPackage {
break
}
var secondDirs []os.DirEntry
secondDirs, err = os.ReadDir(second)
if err != nil {
return nil, nil, nil, errors.Wrapf(err, "读取模版文件夹[%s]失败!", second)
}
for j := 0; j < len(secondDirs); j++ {
if secondDirs[j].Name() == ".DS_Store" {
continue
}
three := filepath.Join(second, secondDirs[j].Name())View on GitHub (pinned to 3136500ef3)
Solutions
- Check server config.yaml: auto-code.root and auto-code.server must resolve to the directory that actually contains resource/<template>.
- Verify the template folder exists at the joined path printed in the error message and create/restore it if missing.
- Fix the entity.Template value stored in the sys_auto_code_packages record (or re-create the package) so it matches an existing folder.
- Ensure the process user has read access to the path.
Example fix
// before: config.yaml auto-code: root: /home/me/old-project // after auto-code: root: . server: . # so ./resource/<template> resolves
Defensive patterns
Strategy: validation
Validate before calling
dir := filepath.Join(cfg.AutoCode.Root, cfg.AutoCode.Server, "resource", entity.Template)
if info, err := os.Stat(dir); err != nil || !info.IsDir() {
return fmt.Errorf("模板目录 %s 不存在,请检查 auto-code.root/server 配置", dir)
} Try / catch
code, asts, creates, err := pkgSvc.CreateTemp(ctx, entity, info)
if err != nil && strings.Contains(err.Error(), "读取模版文件夹") {
log.Printf("模板目录缺失: %v", err)
return fmt.Errorf("请确认 auto-code 配置与 resource/%s 模板目录", entity.Template)
} Prevention
- Keep auto-code.root and auto-code.server aligned with the actual project layout
- Before creating a package, verify its Template value corresponds to an existing folder
- Ship the whole resource/ tree in deployments
- Stat the template dir in a pre-flight check before starting generation
When it happens
Trigger: Invoking the package code-generation (CreateTemp / package create flow) where the entity.Template name (e.g. "package" or "plugin") has no matching folder under <Root>/<Server>/resource/, or the AutoCode Root/Server config values point at a wrong base path.
Common situations: Config auto-code.root / auto-code.server left at defaults after moving the project; selecting a custom template whose folder was never created; typo in the package's Template field in the DB record; resource folder not copied into a custom root layout.
Related errors
- 读取service文件夹失败!
- 读取plugin文件夹失败!
- 读取模版文件夹失败!
- 未找到 MCP 独立配置文件,请在当前目录、cmd/mcp 目录或通过 -config / GVA_MCP_CONFIG
- 未能自动识别项目根目录,请在 MCP 配置中设置 autocode.root
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/5f5c97a243c0b137.
Report an issue: GitHub.