flipped-aurora/gin-vue-admin · error
[filpath:%s]生成文件失败!
Error message
[filpath:%s]生成文件失败!
What it means
After a template parses successfully, generate executes it against the request.AutoCode data; an execution error is wrapped as '[filpath:%s]生成文件失败!'. This means the template body itself failed while rendering (missing method/field on data, index out of range, custom template function error), not that the file is unreadable.
Source
Thrown at server/service/system/auto_code_template.go:169
return preview, nil
}
func (s *autoCodeTemplate) generate(ctx context.Context, info request.AutoCode, entity model.SysAutoCodePackage) (map[string]strings.Builder, map[string]string, map[string]utilsAst.Ast, error) {
templates, asts, _, err := AutoCodePackage.templates(ctx, entity, info, false)
if err != nil {
return nil, nil, nil, err
}
code := make(map[string]strings.Builder)
for key, create := range templates {
var files *template.Template
files, err = template.New(filepath.Base(key)).Funcs(autocode.GetTemplateFuncMap()).ParseFiles(key)
if err != nil {
return nil, nil, nil, errors.Wrapf(err, "[filpath:%s]读取模版文件失败!", key)
}
var builder strings.Builder
err = files.Execute(&builder, info)
if err != nil {
return nil, nil, nil, errors.Wrapf(err, "[filpath:%s]生成文件失败!", create)
}
code[create] = builder
} // 生成文件
injectedCode, injections, err := renderAutoCodeInjections(info, asts)
if err != nil {
return nil, nil, nil, err
}
for key, builder := range injectedCode {
code[key] = builder
}
// 注入代码
return code, templates, injections, nil
}
func renderAutoCodeInjections(info request.AutoCode, asts map[string]utilsAst.Ast) (map[string]strings.Builder, map[string]utilsAst.Ast, error) {
code := make(map[string]strings.Builder, len(asts))
injections := make(map[string]utilsAst.Ast, len(asts))
for key, value := range asts {View on GitHub (pinned to 3136500ef3)
Solutions
- Read the wrapped cause printed with the error — it names the exact template line/executing action; fix that line in the .tpl.
- Check any custom template functions used exist in autocode.GetTemplateFuncMap and support the input type (e.g. DB column type mapping) for your field definitions.
- If this started after an upgrade, diff your custom .tpl files against the version-matched official templates and update accesses to renamed AutoCode fields.
Example fix
{{/* before: assumes field exists */}}
{{ .TableName .StructName }}
{{/* after: guard */}}
{{ if .StructName }}{{ .TableName .StructName }}{{ end }} Defensive patterns
Strategy: try-catch
Try / catch
out, _, _, err := svc.generate(info, templates, asts)
if err != nil {
if strings.Contains(err.Error(), "生成文件失败") {
// parse wrapped template exec error to locate the failing tpl
log.Printf("template execution failed, check recent .tpl edits: %v", err)
}
return err
} Prevention
- After upgrading gin-vue-admin, diff custom templates against the new official ones.
- Test codegen with a minimal struct definition before large generations.
- Keep custom template funcs registered in GetTemplateFuncMap typed and nil-safe.
When it happens
Trigger: files.Execute(&builder, info) fails during Create or Preview when: the .tpl calls a field/method absent from request.AutoCode, a template func from GetTemplateFuncMap errors (e.g. unmapped DB type), or data assumptions break (nil maps/slices indexed by the template).
Common situations: Custom templates written against an older AutoCode struct after upgrading; unsupported database column type passed into a type-mapping template function; template assumes a non-empty collection the request does not provide.
Related errors
- [filpath:%s]读取模版文件失败!
- [filepath:%s]生成失败!
- [filepath:%s]读取模版文件失败!
- child plugin import cannot be blank or dot imported
- parent plugin does not implement Register
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/732f8b187b3830fb.
Report an issue: GitHub.