{"record":{"id":"42ac1882fb802a59","repo":"flipped-aurora/gin-vue-admin","slug":"s-w","errorCode":null,"errorMessage":"查询自动代码菜单 %s 失败: %w","messagePattern":"查询自动代码菜单 (.+?) 失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_persistence.go","lineNumber":94,"sourceCode":"\tvar existing model.SysBaseMenu\n\terr := tx.Where(\"name = ?\", desired.Name).First(&existing).Error\n\tswitch {\n\tcase err == nil:\n\t\tif existing.Name != desired.Name || existing.Path != desired.Path || existing.Component != desired.Component {\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"%w: name=%s, 已存在 path=%s component=%s, 期望 path=%s component=%s\",\n\t\t\t\terrAutoCodeMenuConflict,\n\t\t\t\tdesired.Name,\n\t\t\t\texisting.Path,\n\t\t\t\texisting.Component,\n\t\t\t\tdesired.Path,\n\t\t\t\tdesired.Component,\n\t\t\t)\n\t\t}\n\t\thistory.MenuID = existing.ID\n\t\treturn nil\n\tcase !errors.Is(err, gorm.ErrRecordNotFound):\n\t\treturn fmt.Errorf(\"查询自动代码菜单 %s 失败: %w\", desired.Name, err)\n\t}\n\n\tif info.AutoCreateBtnAuth && !info.OnlyTemplate {\n\t\tdesired.MenuBtn = []model.SysBaseMenuBtn{\n\t\t\t{Name: \"add\", Desc: \"新增\"},\n\t\t\t{Name: \"batchDelete\", Desc: \"批量删除\"},\n\t\t\t{Name: \"delete\", Desc: \"删除\"},\n\t\t\t{Name: \"edit\", Desc: \"编辑\"},\n\t\t\t{Name: \"info\", Desc: \"详情\"},\n\t\t}\n\t\tif info.HasExcel {\n\t\t\tdesired.MenuBtn = append(desired.MenuBtn,\n\t\t\t\tmodel.SysBaseMenuBtn{Name: \"exportTemplate\", Desc: \"导出模板\"},\n\t\t\t\tmodel.SysBaseMenuBtn{Name: \"exportExcel\", Desc: \"导出Excel\"},\n\t\t\t\tmodel.SysBaseMenuBtn{Name: \"importExcel\", Desc: \"导入Excel\"},\n\t\t\t)\n\t\t}\n\t}","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_persistence.go#L76-L112","documentation":"Thrown by persistAutoCodeMenu in the auto-code persistence service when the GORM query looking up an existing menu with the same name (for idempotent re-creation of auto-generated code menus) fails with an error other than gorm.ErrRecordNotFound. The code only tolerates 'not found' (meaning it should create a new menu); any other DB error is wrapped and returned, aborting the transaction.","triggerScenarios":"Calling Create (auto code) with AutoCreateApi/AutoRemoveCreatedMenu flows where the sys_base_menu SELECT for desired.Name fails: DB connection drop, table missing/corrupted, context cancellation, or a driver-level error during the First/Where lookup.","commonSituations":"Database restarted or connection pool exhausted mid-request; sys_base_menu table not migrated (fresh DB without AutoMigrate); wrong BusinessDB configured so the query hits a database that lacks the menu table; row lock/timeout under concurrent menu writes.","solutions":["Check DB connectivity and that sys_base_menu exists (run migrations / AutoMigrate).","Read the wrapped %w cause in the log to identify the driver error (e.g. 'no such table', 'connection refused').","Verify the request's BusinessDB/package config points at the database that actually hosts the menu table.","Retry the auto-code creation once connectivity is restored; the operation is transactional so no partial menu rows remain."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Go: verify DB reachable and table exists before generation\nif err := db.Exec(\"SELECT 1 FROM sys_base_menu LIMIT 1\").Error; err != nil {\n    return fmt.Errorf(\"sys_base_menu unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"err := createAutoCode(req)\nvar dbErr *gorm.DBError\nif errors.As(err, &dbErr) {\n    // surface wrapped cause: fmt.Sprintf(\"%v\", errors.Unwrap(err))\n    retryAfterReconnect()\n}","preventionTips":["Run AutoMigrate for system tables on startup.","Monitor DB connectivity before long code-generation requests.","Keep BusinessDB config pointing at the correct datasource.","Avoid concurrent menu mutations during generation."],"tags":["gorm","database","auto-code","menu"],"backgroundTag":"db-query-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}