{"record":{"id":"79d3ec0a9eceeed1","repo":"flipped-aurora/gin-vue-admin","slug":"error-79d3ec","errorCode":null,"errorMessage":"自动代码菜单名称冲突","messagePattern":"自动代码菜单名称冲突","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_persistence.go","lineNumber":14,"sourceCode":"package system\n\nimport (\n\t\"context\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n\n\tmodel \"github.com/flipped-aurora/gin-vue-admin/server/model/system\"\n\t\"github.com/flipped-aurora/gin-vue-admin/server/model/system/request\"\n\t\"gorm.io/gorm\"\n)\n\nvar errAutoCodeMenuConflict = errors.New(\"自动代码菜单名称冲突\")\n\nfunc persistAutoCodeMetadata(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tinfo request.AutoCode,\n\tpackageTemplate string,\n\thistory request.SysAutoHistoryCreate,\n) error {\n\tif db == nil {\n\t\treturn errors.New(\"自动代码数据库未初始化\")\n\t}\n\treturn db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {\n\t\tif err := persistAutoCodeAPIs(tx, info, &history); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif err := persistAutoCodeMenu(tx, info, packageTemplate, &history); err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_persistence.go#L1-L32","documentation":"errAutoCodeMenuConflict is returned by persistAutoCodeMenu when auto-creating the auto-code menu finds an existing sys_base_menu row with the same name but a different path or component. Rather than silently reusing a mismatched menu, the transaction aborts so the operator resolves the naming collision. The wrapped error includes the existing and expected path/component.","triggerScenarios":"Creating/persisting auto-code with AutoCreateMenuToSql=true while a menu with the same route name already exists pointing to different path/component values — e.g. a hand-edited menu or a previous generation with different target files.","commonSituations":"Re-generating code after manually renaming a menu's path/component; two structs choosing the same menu name; migrations from other environments that already have the menu registered differently.","solutions":["Read the wrapped error detail (name=, 已存在 path/component, 期望 path/component) and rename one of the two menus.","Update the existing sys_base_menu row's path/component to the expected values if the new generation is authoritative.","Disable 自动创建菜单 (AutoCreateMenuToSql=false) and wire the menu manually if you manage menus by hand.","Retry persistence once the menu name no longer collides; the transaction rolled back so no partial rows remain."],"exampleFix":"// before: existing menu 'order' with component 'view/order/index' conflicts\n// after: rename menu in sys_base_menu or change generated menu name\nUPDATE sys_base_menu SET component = 'view/orderManage/index' WHERE name = 'order';\n-- or regenerate with a different menu name","handlingStrategy":"try-catch","validationCode":"const desiredName = info.structName\nconst existing = await api.getMenuByName(desiredName)\nif (existing && (existing.path !== desiredPath || existing.component !== desiredComponent)) {\n  throw new Error(`自动代码菜单名称冲突: name=${desiredName}`)\n}","typeGuard":null,"tryCatchPattern":"err := persistAutoCodeMetadata(ctx, db, info, template, history)\nif errors.Is(err, errAutoCodeMenuConflict) {\n    // surface wrapped detail: name=, existing path/component, expected path/component\n    log.Printf(\"menu conflict: %v\", err)\n    return err // let user resolve naming, transaction already rolled back\n}","preventionTips":["Keep menu names unique per project and derive them from struct names consistently.","Avoid hand-editing auto-generated menus' name/path/component.","Run TestPersistAutoCodeMetadataRejectsSameNameDifferentMenu in CI when touching menu persistence."],"tags":["menu-conflict","autocode","database"],"backgroundTag":"name-conflict","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}