flipped-aurora/gin-vue-admin · error
存在无效API
Error message
存在无效API
What it means
ensureApisExist counts SysApi rows matching the supplied apiIDs and requires an exact match with the number of (deduplicated) ids; any id that does not correspond to an existing sys_api row causes this error. It protects CLI-API bindings from referencing deleted or never-existing APIs.
Source
Thrown at server/plugin/ai/service/sys_cli.go:298
if excludeID > 0 {
query = query.Where("id <> ?", excludeID)
}
if err := query.First(&existing).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return false, nil
}
return false, err
}
return true, nil
}
func (s *cliService) ensureApisExist(ctx context.Context, apiIDs []uint) error {
var count int64
if err := global.GVA_DB.WithContext(ctx).Model(&sysModel.SysApi{}).Where("id IN ?", apiIDs).Count(&count).Error; err != nil {
return err
}
if count != int64(len(apiIDs)) {
return errors.New("存在无效API")
}
return nil
}
func (s *cliService) listCliBindings(ctx context.Context, cliID uint) ([]sysCliManifestBinding, error) {
var bindings []autoModel.SysCliApi
if err := global.GVA_DB.WithContext(ctx).Where("cli_id = ?", cliID).Order("sort ASC, id ASC, api_id ASC").Find(&bindings).Error; err != nil {
return nil, err
}
if len(bindings) == 0 {
return []sysCliManifestBinding{}, nil
}
apiIDs := make([]uint, 0, len(bindings))
for _, binding := range bindings {
apiIDs = append(apiIDs, binding.ApiID)
}
var apis []sysModel.SysApi
if err := global.GVA_DB.WithContext(ctx).Where("id IN ?", apiIDs).Find(&apis).Error; err != nil {View on GitHub (pinned to 3136500ef3)
Solutions
- Verify every ApiID exists (SELECT id FROM sys_api WHERE id IN (...)) before binding
- Reload the API list from the server so the UI offers only existing APIs
- Remove the stale ids from the bindings payload
- Re-sync environments so both sides share the same sys_api rows
Example fix
// before
apiIDs := []uint{1, 2, 999} // 999 deleted
cliService.AddCliApis(ctx, reqWith(apiIDs))
// after
var count int64
db.Model(&sysModel.SysApi{}).Where("id IN ?", apiIDs).Count(&count)
if count != int64(len(apiIDs)) { return errors.New("some APIs no longer exist") }
cliService.AddCliApis(ctx, reqWith(apiIDs)) Defensive patterns
Strategy: validation
Validate before calling
var count int64
global.GVA_DB.Model(&sysModel.SysApi{}).Where("id IN ?", apiIDs).Count(&count)
if count != int64(len(apiIDs)) {
return errors.New("some apiIds reference non-existent APIs")
} Try / catch
err := cliService.AddCliApis(ctx, req)
if err != nil {
if err.Error() == "存在无效API" {
return fmt.Errorf("one or more APIs were deleted or do not exist; refresh the API list")
}
return err
} Prevention
- Refresh the API picker from the server before each binding operation
- Remove ids of APIs deleted elsewhere instead of reusing cached lists
- Do not copy ids across environments/databases
- Run a periodic integrity check for sys_cli_api rows pointing at missing APIs
When it happens
Trigger: Calling AddCliApis with at least one ApiID that has no matching row in sys_api — e.g. an API deleted by another user, an id from a different environment's database, or a fabricated id in a hand-built request.
Common situations: Frontend kept a stale API list and the referenced API was deleted meanwhile; copying ids between dev/staging databases; importing binding configs exported from another instance; ids referencing plugin-provided APIs that are not installed.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/d4ba1b6715d87261.
Report an issue: GitHub.