{"record":{"id":"062c773975c57670","repo":"flipped-aurora/gin-vue-admin","slug":"cliid","errorCode":null,"errorMessage":"cliId不能为空","messagePattern":"cliId不能为空","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/plugin/ai/service/sys_cli.go","lineNumber":269,"sourceCode":"\treturn res, nil\n}\n\nfunc (s *cliService) getCliAndBindings(ctx context.Context, id uint) (autoModel.SysCli, []sysCliManifestBinding, error) {\n\tcli, err := s.getSysCliByID(ctx, id)\n\tif err != nil {\n\t\treturn autoModel.SysCli{}, nil, err\n\t}\n\tbindings, err := s.listCliBindings(ctx, id)\n\tif err != nil {\n\t\treturn autoModel.SysCli{}, nil, err\n\t}\n\treturn cli, bindings, nil\n}\n\nfunc (s *cliService) getSysCliByID(ctx context.Context, id uint) (autoModel.SysCli, error) {\n\tvar cli autoModel.SysCli\n\tif id == 0 {\n\t\treturn cli, errors.New(\"cliId不能为空\")\n\t}\n\tif err := global.GVA_DB.WithContext(ctx).First(&cli, \"id = ?\", id).Error; err != nil {\n\t\treturn cli, err\n\t}\n\treturn cli, nil\n}\n\nfunc (s *cliService) sysCliNameExists(ctx context.Context, name string, excludeID uint) (bool, error) {\n\tvar existing autoModel.SysCli\n\tquery := global.GVA_DB.WithContext(ctx).Where(\"name = ?\", name)\n\tif excludeID > 0 {\n\t\tquery = query.Where(\"id <> ?\", excludeID)\n\t}\n\tif err := query.First(&existing).Error; err != nil {\n\t\tif errors.Is(err, gorm.ErrRecordNotFound) {\n\t\t\treturn false, nil\n\t\t}\n\t\treturn false, err","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/plugin/ai/service/sys_cli.go#L251-L287","documentation":"getSysCliByID is the shared loader for a SysCli row used by UpdateCli, DeleteCli, AddCliApis, RemoveCliApis, PreviewApiCommand and getCliAndBindings; it rejects id == 0 with this error because no CLI can have primary key 0. Any public operation that receives a zero CliID funnels into this error.","triggerScenarios":"Calling any of the CLI management operations (update/delete/add-apis/remove-apis/preview) with CliID or ID set to 0, typically because the request field was never populated.","commonSituations":"Frontend action fired before a CLI row was selected; JSON body key mismatch (e.g. \"cli_id\" vs the Go field) so CliID unmarshals to 0; scripted bulk calls where the id lookup failed upstream and the zero value was propagated.","solutions":["Populate CliID/ID with the actual CLI record id before calling","Verify the JSON field names match the Go request struct tags","Check on the caller side that the selected CLI exists and its id is non-zero","Refresh the selection state in the UI so a stale/empty selection cannot be submitted"],"exampleFix":"// before\nreq := autoReq.DeleteSysCliRequest{ID: 0} // field never set\ncliService.DeleteCli(ctx, req)\n// after\nif req.ID == 0 { return errors.New(\"no CLI selected\") }\ncliService.DeleteCli(ctx, req)","handlingStrategy":"validation","validationCode":"if cliID == 0 {\n    return errors.New(\"a CLI must be selected before performing this operation\")\n}","typeGuard":"func cliSelected(req autoReq.DeleteSysCliRequest) bool {\n    return req.ID != 0\n}","tryCatchPattern":"err := cliService.DeleteCli(ctx, req)\nif err != nil {\n    if err.Error() == \"cliId不能为空\" {\n        return fmt.Errorf(\"no CLI id supplied; select a CLI first\")\n    }\n    return err\n}","preventionTips":["Never issue CLI operations without a concrete row id","Check JSON key names against the request struct tags","Guard UI actions so they are disabled until a CLI row is selected","Verify upstream id lookups succeeded before passing ids along"],"tags":["validation","go","plugin-ai","cli"],"backgroundTag":"required-field-missing","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}