flipped-aurora/gin-vue-admin · error
自动代码菜单名称冲突
Error message
自动代码菜单名称冲突
What it means
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.
Source
Thrown at server/service/system/auto_code_persistence.go:14
package system
import (
"context"
"encoding/json"
"errors"
"fmt"
model "github.com/flipped-aurora/gin-vue-admin/server/model/system"
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
"gorm.io/gorm"
)
var errAutoCodeMenuConflict = errors.New("自动代码菜单名称冲突")
func persistAutoCodeMetadata(
ctx context.Context,
db *gorm.DB,
info request.AutoCode,
packageTemplate string,
history request.SysAutoHistoryCreate,
) error {
if db == nil {
return errors.New("自动代码数据库未初始化")
}
return db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
if err := persistAutoCodeAPIs(tx, info, &history); err != nil {
return err
}
if err := persistAutoCodeMenu(tx, info, packageTemplate, &history); err != nil {
return err
}View on GitHub (pinned to 3136500ef3)
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.
Example fix
// before: existing menu 'order' with component 'view/order/index' conflicts // after: rename menu in sys_base_menu or change generated menu name UPDATE sys_base_menu SET component = 'view/orderManage/index' WHERE name = 'order'; -- or regenerate with a different menu name
Defensive patterns
Strategy: try-catch
Validate before calling
const desiredName = info.structName
const existing = await api.getMenuByName(desiredName)
if (existing && (existing.path !== desiredPath || existing.component !== desiredComponent)) {
throw new Error(`自动代码菜单名称冲突: name=${desiredName}`)
} Try / catch
err := persistAutoCodeMetadata(ctx, db, info, template, history)
if errors.Is(err, errAutoCodeMenuConflict) {
// surface wrapped detail: name=, existing path/component, expected path/component
log.Printf("menu conflict: %v", err)
return err // let user resolve naming, transaction already rolled back
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/79d3ec0a9eceeed1.
Report an issue: GitHub.