flipped-aurora/gin-vue-admin · error
插件初始化文件缺少 []model.%s 数组
Error message
插件初始化文件缺少 []model.%s 数组
What it means
The initialize file parsed successfully, but ast.FindArray found no []model.<Selector> array (e.g. []model.SysMenu) with the expected selector name, so loadPluginInitializeArray returns errors.Errorf '插件初始化文件缺少 []model.%s 数组'.
Source
Thrown at server/service/system/auto_code_plugin.go:1104
}
func loadPluginInitializeArray(pluginName, fileName, selectorName string) (string, *token.FileSet, *goast.File, *goast.CompositeLit, error) {
path, err := pluginPath(global.GVA_CONFIG.AutoCode.Server, pluginName, "initialize", fileName)
if err != nil {
return "", nil, nil, nil, err
}
src, err := os.ReadFile(path)
if err != nil {
return "", nil, nil, nil, errors.Wrap(err, "读取插件初始化文件失败")
}
fileSet := token.NewFileSet()
astFile, err := parser.ParseFile(fileSet, path, src, parser.ParseComments)
if err != nil {
return "", nil, nil, nil, errors.Wrap(err, "解析插件初始化文件失败")
}
arrayAst := ast.FindArray(astFile, "model", selectorName)
if arrayAst == nil {
return "", nil, nil, nil, errors.Errorf("插件初始化文件缺少 []model.%s 数组", selectorName)
}
return path, fileSet, astFile, arrayAst, nil
}
func writePluginInitializeFile(path string, fileSet *token.FileSet, astFile *goast.File) error {
var out bytes.Buffer
if err := printer.Fprint(&out, fileSet, astFile); err != nil {
return errors.Wrap(err, "打印插件初始化文件失败")
}
if err := os.WriteFile(path, out.Bytes(), 0666); err != nil {
return errors.Wrap(err, "写入插件初始化文件失败")
}
return nil
}
View on GitHub (pinned to 3136500ef3)
Solutions
- Ensure the initialize file declares the array as []model.SysMenu{...} (matching the expected selector)
- Regenerate the plugin initialize files with the current code generator version
- Compare with a freshly generated plugin's initialize file and align the structure
- Check you are initializing the correct plugin name
- If the array is intentionally empty, keep the declaration (an empty literal is fine) rather than deleting it
Example fix
// before: wrong element type
var menus = []sysModel.Menu{...}
// after
var M = []model.SysMenu{ ... } Defensive patterns
Strategy: validation
Validate before calling
// grep for the expected array declaration before init
data, _ := os.ReadFile(path)
varName := "SysMenu" // per init kind
marker := "[]model." + varName + "{"
if !bytes.Contains(data, []byte(marker)) {
return fmt.Errorf("initialize file lacks %s array", marker)
} Try / catch
err := pluginSvc.InitDictionary(ctx, pluginName)
if err != nil && strings.Contains(err.Error(), "插件初始化文件缺少 []model.") {
// regenerate the plugin initialize files with the current generator version
} Prevention
- Keep plugin templates and server generator versions in sync
- Do not rename the array variable or its []model.X element type in initialize files
- Keep the array declared even when empty (var X = []model.SysMenu{})
- Cross-check against a freshly generated plugin's initialize file
When it happens
Trigger: InitMenu/InitAPI/InitDictionary on a plugin whose initialize file is valid Go but does not declare the expected array variable of type []model.X — wrong file, renamed variable, or changed element type.
Common situations: Plugin template version mismatch (older initialize files using a different structure); user renamed the array variable or element type; wrong plugin selected so the file exists but holds a different array; generator produced an empty or commented-out array.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/97a00f2d3a8a8c04.
Report an issue: GitHub.