{"record":{"id":"97a00f2d3a8a8c04","repo":"flipped-aurora/gin-vue-admin","slug":"model-s","errorCode":null,"errorMessage":"插件初始化文件缺少 []model.%s 数组","messagePattern":"插件初始化文件缺少 \\[\\]model\\.(.+?) 数组","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_plugin.go","lineNumber":1104,"sourceCode":"}\n\nfunc loadPluginInitializeArray(pluginName, fileName, selectorName string) (string, *token.FileSet, *goast.File, *goast.CompositeLit, error) {\n\tpath, err := pluginPath(global.GVA_CONFIG.AutoCode.Server, pluginName, \"initialize\", fileName)\n\tif err != nil {\n\t\treturn \"\", nil, nil, nil, err\n\t}\n\tsrc, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn \"\", nil, nil, nil, errors.Wrap(err, \"读取插件初始化文件失败\")\n\t}\n\tfileSet := token.NewFileSet()\n\tastFile, err := parser.ParseFile(fileSet, path, src, parser.ParseComments)\n\tif err != nil {\n\t\treturn \"\", nil, nil, nil, errors.Wrap(err, \"解析插件初始化文件失败\")\n\t}\n\tarrayAst := ast.FindArray(astFile, \"model\", selectorName)\n\tif arrayAst == nil {\n\t\treturn \"\", nil, nil, nil, errors.Errorf(\"插件初始化文件缺少 []model.%s 数组\", selectorName)\n\t}\n\treturn path, fileSet, astFile, arrayAst, nil\n}\n\nfunc writePluginInitializeFile(path string, fileSet *token.FileSet, astFile *goast.File) error {\n\tvar out bytes.Buffer\n\tif err := printer.Fprint(&out, fileSet, astFile); err != nil {\n\t\treturn errors.Wrap(err, \"打印插件初始化文件失败\")\n\t}\n\tif err := os.WriteFile(path, out.Bytes(), 0666); err != nil {\n\t\treturn errors.Wrap(err, \"写入插件初始化文件失败\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":1086,"sourceCodeEnd":1119,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_plugin.go#L1086-L1119","documentation":"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 数组'.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: wrong element type\nvar menus = []sysModel.Menu{...}\n// after\nvar M = []model.SysMenu{ ... }","handlingStrategy":"validation","validationCode":"// grep for the expected array declaration before init\ndata, _ := os.ReadFile(path)\nvarName := \"SysMenu\" // per init kind\nmarker := \"[]model.\" + varName + \"{\"\nif !bytes.Contains(data, []byte(marker)) {\n    return fmt.Errorf(\"initialize file lacks %s array\", marker)\n}","typeGuard":null,"tryCatchPattern":"err := pluginSvc.InitDictionary(ctx, pluginName)\nif err != nil && strings.Contains(err.Error(), \"插件初始化文件缺少 []model.\") {\n    // regenerate the plugin initialize files with the current generator version\n}","preventionTips":["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"],"tags":["go","ast","plugin-initialization","code-generation"],"backgroundTag":"initialize-array-missing","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}