From 95221d9acec8f2000de192f24404e83f37b2b75a Mon Sep 17 00:00:00 2001 From: Rodrigo Villablanca Date: Tue, 17 Nov 2020 00:32:36 -0300 Subject: [PATCH] GroupStore migration (#15795) * Migration completed * Fix tests * Fix tests * Fix tests * Suggestions * Trigger CI * Suggestions * Merge with master * Migration completed * Fix typo * fix err check Co-authored-by: Mattermod Co-authored-by: Agniva De Sarker --- api4/ldap.go | 3 +- app/group.go | 321 +++++++-- app/notification.go | 10 +- app/syncables.go | 7 +- app/user.go | 2 +- i18n/en.json | 88 +-- model/group.go | 2 +- store/opentracinglayer/opentracinglayer.go | 88 +-- store/retrylayer/retrylayer.go | 792 ++++++++++++++++++--- store/sqlstore/group_store.go | 349 +++++---- store/store.go | 88 +-- store/storetest/group_store.go | 62 +- store/storetest/mocks/GroupStore.go | 440 +++++------- store/timerlayer/timerlayer.go | 88 +-- 14 files changed, 1524 insertions(+), 816 deletions(-) diff --git a/api4/ldap.go b/api4/ldap.go index ea66d4fd31..e8d6570504 100644 --- a/api4/ldap.go +++ b/api4/ldap.go @@ -4,7 +4,6 @@ package api4 import ( - "database/sql" "encoding/json" "mime/multipart" "net/http" @@ -166,7 +165,7 @@ func linkLdapGroup(c *Context, w http.ResponseWriter, r *http.Request) { } group, err := c.App.GetGroupByRemoteID(ldapGroup.RemoteId, model.GroupSourceLdap) - if err != nil && err.DetailedError != sql.ErrNoRows.Error() { + if err != nil && err.Id != "app.group.no_rows" { c.Err = err return } diff --git a/app/group.go b/app/group.go index bc9cacc609..8cda73f115 100644 --- a/app/group.go +++ b/app/group.go @@ -12,27 +12,84 @@ import ( ) func (a *App) GetGroup(id string) (*model.Group, *model.AppError) { - return a.Srv().Store.Group().Get(id) + group, err := a.Srv().Store.Group().Get(id) + if err != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("GetGroup", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("GetGroup", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return group, nil } func (a *App) GetGroupByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError) { - return a.Srv().Store.Group().GetByName(name, opts) + group, err := a.Srv().Store.Group().GetByName(name, opts) + if err != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("GetGroupByName", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("GetGroupByName", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return group, nil } func (a *App) GetGroupByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError) { - return a.Srv().Store.Group().GetByRemoteID(remoteID, groupSource) + group, err := a.Srv().Store.Group().GetByRemoteID(remoteID, groupSource) + if err != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("GetGroupByRemoteID", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("GetGroupByRemoteID", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return group, nil } func (a *App) GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) { - return a.Srv().Store.Group().GetAllBySource(groupSource) + groups, err := a.Srv().Store.Group().GetAllBySource(groupSource) + if err != nil { + return nil, model.NewAppError("GetGroupsBySource", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + + return groups, nil } func (a *App) GetGroupsByUserId(userId string) ([]*model.Group, *model.AppError) { - return a.Srv().Store.Group().GetByUser(userId) + groups, err := a.Srv().Store.Group().GetByUser(userId) + if err != nil { + return nil, model.NewAppError("GetGroupsByUserId", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + + return groups, nil } func (a *App) CreateGroup(group *model.Group) (*model.Group, *model.AppError) { - return a.Srv().Store.Group().Create(group) + group, err := a.Srv().Store.Group().Create(group) + if err != nil { + var invErr *store.ErrInvalidInput + var appErr *model.AppError + switch { + case errors.As(err, &appErr): + return nil, appErr + case errors.As(err, &invErr): + return nil, model.NewAppError("CreateGroup", "app.group.id.app_error", nil, invErr.Error(), http.StatusBadRequest) + default: + return nil, model.NewAppError("CreateGroup", "app.insert_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return group, nil } func (a *App) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) { @@ -44,7 +101,20 @@ func (a *App) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) { a.Publish(messageWs) } - return updatedGroup, err + if err != nil { + var nfErr *store.ErrNotFound + var appErr *model.AppError + switch { + case errors.As(err, &appErr): + return nil, appErr + case errors.As(err, &nfErr): + return nil, model.NewAppError("UpdateGroup", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("UpdateGroup", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return updatedGroup, nil } func (a *App) DeleteGroup(groupID string) (*model.Group, *model.AppError) { @@ -56,42 +126,88 @@ func (a *App) DeleteGroup(groupID string) (*model.Group, *model.AppError) { a.Publish(messageWs) } - return deletedGroup, err + if err != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("DeleteGroup", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("DeleteGroup", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return deletedGroup, nil } func (a *App) GetGroupMemberCount(groupID string) (int64, *model.AppError) { - return a.Srv().Store.Group().GetMemberCount(groupID) + count, err := a.Srv().Store.Group().GetMemberCount(groupID) + if err != nil { + return 0, model.NewAppError("GetGroupMemberCount", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + + return count, nil } func (a *App) GetGroupMemberUsers(groupID string) ([]*model.User, *model.AppError) { - return a.Srv().Store.Group().GetMemberUsers(groupID) + users, err := a.Srv().Store.Group().GetMemberUsers(groupID) + if err != nil { + return nil, model.NewAppError("GetGroupMemberUsers", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + + return users, nil } func (a *App) GetGroupMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, int, *model.AppError) { members, err := a.Srv().Store.Group().GetMemberUsersPage(groupID, page, perPage) if err != nil { - return nil, 0, err + return nil, 0, model.NewAppError("GetGroupMemberUsersPage", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } - count, err := a.GetGroupMemberCount(groupID) - if err != nil { - return nil, 0, err + count, appErr := a.GetGroupMemberCount(groupID) + if appErr != nil { + return nil, 0, appErr } return members, int(count), nil } func (a *App) UpsertGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) { - return a.Srv().Store.Group().UpsertMember(groupID, userID) + groupMember, err := a.Srv().Store.Group().UpsertMember(groupID, userID) + if err != nil { + var invErr *store.ErrInvalidInput + var appErr *model.AppError + switch { + case errors.As(err, &appErr): + return nil, appErr + case errors.As(err, &invErr): + return nil, model.NewAppError("UpsertGroupMember", "app.group.uniqueness_error", nil, invErr.Error(), http.StatusBadRequest) + default: + return nil, model.NewAppError("UpsertGroupMember", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return groupMember, nil } func (a *App) DeleteGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) { - return a.Srv().Store.Group().DeleteMember(groupID, userID) + groupMember, err := a.Srv().Store.Group().DeleteMember(groupID, userID) + if err != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("DeleteGroupMember", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("DeleteGroupMember", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return groupMember, nil } func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) { gs, err := a.Srv().Store.Group().GetGroupSyncable(groupSyncable.GroupId, groupSyncable.SyncableId, groupSyncable.Type) - if err != nil && err.Id != "store.sql_group.no_rows" { - return nil, err + var notFoundErr *store.ErrNotFound + if err != nil && !errors.As(err, ¬FoundErr) { + return nil, model.NewAppError("UpsertGroupSyncable", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } // reject the syncable creation if the group isn't already associated to the parent team @@ -122,7 +238,7 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr var teamGroups []*model.GroupWithSchemeAdmin teamGroups, err = a.Srv().Store.Group().GetGroupsByTeam(channel.TeamId, model.GroupSearchOpts{}) if err != nil { - return nil, err + return nil, model.NewAppError("UpsertGroupSyncable", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } var permittedGroup bool for _, teamGroup := range teamGroups { @@ -132,12 +248,12 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr } } if !permittedGroup { - return nil, model.NewAppError("App.UpsertGroupSyncable", "group_not_associated_to_synced_team", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("UpsertGroupSyncable", "group_not_associated_to_synced_team", nil, "", http.StatusBadRequest) } } else { - _, err = a.UpsertGroupSyncable(model.NewGroupTeam(groupSyncable.GroupId, team.Id, groupSyncable.AutoAdd)) - if err != nil { - return nil, err + _, appErr := a.UpsertGroupSyncable(model.NewGroupTeam(groupSyncable.GroupId, team.Id, groupSyncable.AutoAdd)) + if appErr != nil { + return nil, appErr } } } @@ -145,12 +261,27 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr if gs == nil { gs, err = a.Srv().Store.Group().CreateGroupSyncable(groupSyncable) if err != nil { - return nil, err + var nfErr *store.ErrNotFound + var appErr *model.AppError + switch { + case errors.As(err, &appErr): + return nil, appErr + case errors.As(err, &nfErr): + return nil, model.NewAppError("UpsertGroupSyncable", "store.sql_channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("UpsertGroupSyncable", "app.insert_error", nil, err.Error(), http.StatusInternalServerError) + } } } else { gs, err = a.Srv().Store.Group().UpdateGroupSyncable(groupSyncable) if err != nil { - return nil, err + var appErr *model.AppError + switch { + case errors.As(err, &appErr): + return nil, appErr + default: + return nil, model.NewAppError("UpsertGroupSyncable", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + } } } @@ -167,24 +298,48 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr } func (a *App) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) { - return a.Srv().Store.Group().GetGroupSyncable(groupID, syncableID, syncableType) + group, err := a.Srv().Store.Group().GetGroupSyncable(groupID, syncableID, syncableType) + if err != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("GetGroupSyncable", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("GetGroupSyncable", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return group, nil } func (a *App) GetGroupSyncables(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) { - return a.Srv().Store.Group().GetAllGroupSyncablesByGroupId(groupID, syncableType) + groups, err := a.Srv().Store.Group().GetAllGroupSyncablesByGroupId(groupID, syncableType) + if err != nil { + return nil, model.NewAppError("GetGroupSyncables", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + + return groups, nil } func (a *App) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) { - var gs *model.GroupSyncable - var err *model.AppError - if groupSyncable.DeleteAt == 0 { // updating a *deleted* GroupSyncable, so no need to ensure the GroupTeam is present (as done in the upsert) - gs, err = a.Srv().Store.Group().UpdateGroupSyncable(groupSyncable) - } else { - // do an upsert to ensure that there's an associated GroupTeam - gs, err = a.UpsertGroupSyncable(groupSyncable) + gs, err := a.Srv().Store.Group().UpdateGroupSyncable(groupSyncable) + if err != nil { + var appErr *model.AppError + switch { + case errors.As(err, &appErr): + return nil, appErr + default: + return nil, model.NewAppError("UpdateGroupSyncable", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return gs, nil } + + // do an upsert to ensure that there's an associated GroupTeam + gs, err := a.UpsertGroupSyncable(groupSyncable) if err != nil { return nil, err } @@ -195,20 +350,38 @@ func (a *App) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr func (a *App) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) { gs, err := a.Srv().Store.Group().DeleteGroupSyncable(groupID, syncableID, syncableType) if err != nil { - return nil, err + var invErr *store.ErrInvalidInput + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("DeleteGroupSyncable", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + case errors.As(err, &invErr): + return nil, model.NewAppError("DeleteGroupSyncable", "app.group.group_syncable_already_deleted", nil, invErr.Error(), http.StatusBadRequest) + default: + return nil, model.NewAppError("DeleteGroupSyncable", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + } } // if a GroupTeam is being deleted delete all associated GroupChannels if gs.Type == model.GroupSyncableTypeTeam { allGroupChannels, err := a.Srv().Store.Group().GetAllGroupSyncablesByGroupId(gs.GroupId, model.GroupSyncableTypeChannel) if err != nil { - return nil, err + return nil, model.NewAppError("DeleteGroupSyncable", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } for _, groupChannel := range allGroupChannels { _, err = a.Srv().Store.Group().DeleteGroupSyncable(groupChannel.GroupId, groupChannel.SyncableId, groupChannel.Type) if err != nil { - return nil, err + var invErr *store.ErrInvalidInput + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("DeleteGroupSyncable", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + case errors.As(err, &invErr): + return nil, model.NewAppError("DeleteGroupSyncable", "app.group.group_syncable_already_deleted", nil, invErr.Error(), http.StatusBadRequest) + default: + return nil, model.NewAppError("DeleteGroupSyncable", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + } } } } @@ -227,30 +400,50 @@ func (a *App) DeleteGroupSyncable(groupID string, syncableID string, syncableTyp } func (a *App) TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, *model.AppError) { - return a.Srv().Store.Group().TeamMembersToAdd(since, teamID) + userTeams, err := a.Srv().Store.Group().TeamMembersToAdd(since, teamID) + if err != nil { + return nil, model.NewAppError("TeamMembersToAdd", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + + return userTeams, nil } func (a *App) ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, *model.AppError) { - return a.Srv().Store.Group().ChannelMembersToAdd(since, channelID) + userChannels, err := a.Srv().Store.Group().ChannelMembersToAdd(since, channelID) + if err != nil { + return nil, model.NewAppError("ChannelMembersToAdd", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + + return userChannels, nil } func (a *App) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError) { - return a.Srv().Store.Group().TeamMembersToRemove(teamID) + teamMembers, err := a.Srv().Store.Group().TeamMembersToRemove(teamID) + if err != nil { + return nil, model.NewAppError("TeamMembersToRemove", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + + return teamMembers, nil } func (a *App) ChannelMembersToRemove(teamID *string) ([]*model.ChannelMember, *model.AppError) { - return a.Srv().Store.Group().ChannelMembersToRemove(teamID) + channelMembers, err := a.Srv().Store.Group().ChannelMembersToRemove(teamID) + if err != nil { + return nil, model.NewAppError("ChannelMembersToRemove", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + + return channelMembers, nil } func (a *App) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, int, *model.AppError) { groups, err := a.Srv().Store.Group().GetGroupsByChannel(channelId, opts) if err != nil { - return nil, 0, err + return nil, 0, model.NewAppError("GetGroupsByChannel", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } count, err := a.Srv().Store.Group().CountGroupsByChannel(channelId, opts) if err != nil { - return nil, 0, err + return nil, 0, model.NewAppError("GetGroupsByChannel", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } return groups, int(count), nil @@ -260,12 +453,12 @@ func (a *App) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ( func (a *App) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, int, *model.AppError) { groups, err := a.Srv().Store.Group().GetGroupsByTeam(teamId, opts) if err != nil { - return nil, 0, err + return nil, 0, model.NewAppError("GetGroupsByTeam", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } count, err := a.Srv().Store.Group().CountGroupsByTeam(teamId, opts) if err != nil { - return nil, 0, err + return nil, 0, model.NewAppError("GetGroupsByTeam", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } return groups, int(count), nil @@ -274,14 +467,19 @@ func (a *App) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*mod func (a *App) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError) { groupsAssociatedByChannelId, err := a.Srv().Store.Group().GetGroupsAssociatedToChannelsByTeam(teamId, opts) if err != nil { - return nil, err + return nil, model.NewAppError("GetGroupsAssociatedToChannelsByTeam", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } return groupsAssociatedByChannelId, nil } func (a *App) GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) { - return a.Srv().Store.Group().GetGroups(page, perPage, opts) + groups, err := a.Srv().Store.Group().GetGroups(page, perPage, opts) + if err != nil { + return nil, model.NewAppError("GetGroups", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + + return groups, nil } // TeamMembersMinusGroupMembers returns the set of users on the given team minus the set of users in the given @@ -292,7 +490,7 @@ func (a *App) GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model func (a *App) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, int64, *model.AppError) { users, err := a.Srv().Store.Group().TeamMembersMinusGroupMembers(teamID, groupIDs, page, perPage) if err != nil { - return nil, 0, err + return nil, 0, model.NewAppError("TeamMembersMinusGroupMembers", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } // parse all group ids of all users @@ -310,9 +508,9 @@ func (a *App) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, pag } // retrieve groups from DB - groups, err := a.GetGroupsByIDs(allUsersGroupIDSlice) - if err != nil { - return nil, 0, err + groups, appErr := a.GetGroupsByIDs(allUsersGroupIDSlice) + if appErr != nil { + return nil, 0, appErr } // map groups by id @@ -334,13 +532,18 @@ func (a *App) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, pag totalCount, err := a.Srv().Store.Group().CountTeamMembersMinusGroupMembers(teamID, groupIDs) if err != nil { - return nil, 0, err + return nil, 0, model.NewAppError("TeamMembersMinusGroupMembers", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } return users, totalCount, nil } func (a *App) GetGroupsByIDs(groupIDs []string) ([]*model.Group, *model.AppError) { - return a.Srv().Store.Group().GetByIDs(groupIDs) + groups, err := a.Srv().Store.Group().GetByIDs(groupIDs) + if err != nil { + return nil, model.NewAppError("GetGroupsByIDs", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + } + + return groups, nil } // ChannelMembersMinusGroupMembers returns the set of users in the given channel minus the set of users in the given @@ -351,7 +554,7 @@ func (a *App) GetGroupsByIDs(groupIDs []string) ([]*model.Group, *model.AppError func (a *App) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, int64, *model.AppError) { users, err := a.Srv().Store.Group().ChannelMembersMinusGroupMembers(channelID, groupIDs, page, perPage) if err != nil { - return nil, 0, err + return nil, 0, model.NewAppError("ChannelMembersMinusGroupMembers", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } // parse all group ids of all users @@ -369,9 +572,9 @@ func (a *App) ChannelMembersMinusGroupMembers(channelID string, groupIDs []strin } // retrieve groups from DB - groups, err := a.GetGroupsByIDs(allUsersGroupIDSlice) - if err != nil { - return nil, 0, err + groups, appErr := a.GetGroupsByIDs(allUsersGroupIDSlice) + if appErr != nil { + return nil, 0, appErr } // map groups by id @@ -393,7 +596,7 @@ func (a *App) ChannelMembersMinusGroupMembers(channelID string, groupIDs []strin totalCount, err := a.Srv().Store.Group().CountChannelMembersMinusGroupMembers(channelID, groupIDs) if err != nil { - return nil, 0, err + return nil, 0, model.NewAppError("ChannelMembersMinusGroupMembers", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } return users, totalCount, nil } @@ -403,7 +606,7 @@ func (a *App) ChannelMembersMinusGroupMembers(channelID string, groupIDs []strin func (a *App) UserIsInAdminRoleGroup(userID, syncableID string, syncableType model.GroupSyncableType) (bool, *model.AppError) { groupIDs, err := a.Srv().Store.Group().AdminRoleGroupsForSyncableMember(userID, syncableID, syncableType) if err != nil { - return false, err + return false, model.NewAppError("UserIsInAdminRoleGroup", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } if len(groupIDs) == 0 { diff --git a/app/notification.go b/app/notification.go index fb1607d925..7eb3b26891 100644 --- a/app/notification.go +++ b/app/notification.go @@ -789,7 +789,7 @@ func (a *App) allowGroupMentions(post *model.Post) bool { // getGroupsAllowedForReferenceInChannel returns a map of groups allowed for reference in a given channel and team. func (a *App) getGroupsAllowedForReferenceInChannel(channel *model.Channel, team *model.Team) (map[string]*model.Group, *model.AppError) { - var err *model.AppError + var err error groupsMap := make(map[string]*model.Group) opts := model.GroupSearchOpts{FilterAllowReference: true} @@ -801,7 +801,7 @@ func (a *App) getGroupsAllowedForReferenceInChannel(channel *model.Channel, team groups, err = a.Srv().Store.Group().GetGroupsByTeam(team.Id, opts) } if err != nil { - return nil, err + return nil, model.NewAppError("getGroupsAllowedForReferenceInChannel", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } for _, group := range groups { if group.Group.Name != nil { @@ -813,7 +813,7 @@ func (a *App) getGroupsAllowedForReferenceInChannel(channel *model.Channel, team groups, err := a.Srv().Store.Group().GetGroups(0, 0, opts) if err != nil { - return nil, err + return nil, model.NewAppError("getGroupsAllowedForReferenceInChannel", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } for _, group := range groups { if group.Name != nil { @@ -845,7 +845,7 @@ func (a *App) getMentionKeywordsInChannel(profiles map[string]*model.User, allow // insertGroupMentions adds group members in the channel to Mentions, adds group members not in the channel to OtherPotentialMentions // returns false if no group members present in the team that the channel belongs to func (a *App) insertGroupMentions(group *model.Group, channel *model.Channel, profileMap map[string]*model.User, mentions *ExplicitMentions) (bool, *model.AppError) { - var err *model.AppError + var err error var groupMembers []*model.User outOfChannelGroupMembers := []*model.User{} isGroupOrDirect := channel.IsGroupOrDirect() @@ -857,7 +857,7 @@ func (a *App) insertGroupMentions(group *model.Group, channel *model.Channel, pr } if err != nil { - return false, err + return false, model.NewAppError("insertGroupMentions", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } if mentions.Mentions == nil { diff --git a/app/syncables.go b/app/syncables.go index d208e46436..8ffe737516 100644 --- a/app/syncables.go +++ b/app/syncables.go @@ -195,7 +195,7 @@ func (a *App) deleteGroupConstrainedChannelMemberships(channelID *string) error func (a *App) SyncSyncableRoles(syncableID string, syncableType model.GroupSyncableType) *model.AppError { permittedAdmins, err := a.Srv().Store.Group().PermittedSyncableAdmins(syncableID, syncableType) if err != nil { - return err + return model.NewAppError("SyncSyncableRoles", "app.select_error", nil, err.Error(), http.StatusInternalServerError) } a.Log().Info( @@ -208,14 +208,13 @@ func (a *App) SyncSyncableRoles(syncableID string, syncableType model.GroupSynca case model.GroupSyncableTypeTeam: nErr := a.Srv().Store.Team().UpdateMembersRole(syncableID, permittedAdmins) if nErr != nil { - // TODO: Should we change the key "store.update_error" to "app.update_error"? It is very general and changing it now will modify lots of files - return model.NewAppError("App.SyncSyncableRoles", "store.update_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("App.SyncSyncableRoles", "app.update_error", nil, nErr.Error(), http.StatusInternalServerError) } return nil case model.GroupSyncableTypeChannel: nErr := a.Srv().Store.Channel().UpdateMembersRole(syncableID, permittedAdmins) if nErr != nil { - return model.NewAppError("App.SyncSyncableRoles", "store.update_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("App.SyncSyncableRoles", "app.update_error", nil, nErr.Error(), http.StatusInternalServerError) } return nil default: diff --git a/app/user.go b/app/user.go index ef997c4f28..1f7674e5ff 100644 --- a/app/user.go +++ b/app/user.go @@ -1655,7 +1655,7 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError { } if err := a.Srv().Store.Group().PermanentDeleteMembersByUser(user.Id); err != nil { - return err + return model.NewAppError("PermanentDeleteUser", "app.group.permanent_delete_members_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) } if err := a.Srv().Store.Post().PermanentDeleteByUser(user.Id); err != nil { diff --git a/i18n/en.json b/i18n/en.json index 6f58e74dc7..23a5dc0a27 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -4070,6 +4070,26 @@ "id": "app.file_info.save.app_error", "translation": "Unable to save the file info." }, + { + "id": "app.group.group_syncable_already_deleted", + "translation": "group syncable was already deleted" + }, + { + "id": "app.group.id.app_error", + "translation": "invalid id property for group." + }, + { + "id": "app.group.no_rows", + "translation": "no matching group found" + }, + { + "id": "app.group.permanent_delete_members_by_user.app_error", + "translation": "Unable to remove the group member with UserID \"{{.UserId}}\"." + }, + { + "id": "app.group.uniqueness_error", + "translation": "group member already exists" + }, { "id": "app.import.attachment.bad_file.error", "translation": "Error reading the file at: \"{{.FilePath}}\"" @@ -4630,6 +4650,10 @@ "id": "app.import.validate_user_teams_import_data.team_name_missing.error", "translation": "Team name missing from User's Team Membership." }, + { + "id": "app.insert_error", + "translation": "insert error" + }, { "id": "app.job.download_export_results_not_enabled", "translation": "DownloadExportResults in config.json is false. Please set this to true to download the results of this job." @@ -5154,6 +5178,10 @@ "id": "app.schemes.is_phase_2_migration_completed.not_completed.app_error", "translation": "This API endpoint is not accessible as required migrations have not yet completed." }, + { + "id": "app.select_error", + "translation": "select error" + }, { "id": "app.session.analytics_session_count.app_error", "translation": "Unable to count the sessions." @@ -5430,6 +5458,10 @@ "id": "app.terms_of_service.get.no_rows.app_error", "translation": "No terms of service found." }, + { + "id": "app.update_error", + "translation": "update error" + }, { "id": "app.upload.create.cannot_upload_to_deleted_channel.app_error", "translation": "Cannot upload to a deleted channel." @@ -7378,10 +7410,6 @@ "id": "model.group.create_at.app_error", "translation": "invalid create at property for group." }, - { - "id": "model.group.delete_at.app_error", - "translation": "invalid delete at property for group." - }, { "id": "model.group.description.app_error", "translation": "invalid description property for group." @@ -7390,10 +7418,6 @@ "id": "model.group.display_name.app_error", "translation": "invalid display name property for group." }, - { - "id": "model.group.id.app_error", - "translation": "invalid id property for group." - }, { "id": "model.group.name.app_error", "translation": "invalid name property for group." @@ -7434,10 +7458,6 @@ "id": "model.group_syncable.syncable_id.app_error", "translation": "invalid syncable id for group syncable." }, - { - "id": "model.group_syncable.type.app_error", - "translation": "invalid type property for group syncable." - }, { "id": "model.guest.is_valid.channel.app_error", "translation": "Invalid channel." @@ -8062,14 +8082,6 @@ "id": "searchengine.bleve.disabled.error", "translation": "Error purging Bleve indexes: engine is disabled" }, - { - "id": "store.insert_error", - "translation": "insert error" - }, - { - "id": "store.select_error", - "translation": "select error" - }, { "id": "store.sql.convert_string_array", "translation": "FromDb: Unable to convert StringArray to *string" @@ -8090,10 +8102,6 @@ "id": "store.sql_channel.get.existing.app_error", "translation": "Unable to find the existing channel." }, - { - "id": "store.sql_channel.get.find.app_error", - "translation": "We encountered an error finding the channel." - }, { "id": "store.sql_channel.save.archived_channel.app_error", "translation": "You can not modify an archived channel." @@ -8130,34 +8138,6 @@ "id": "store.sql_command.update.missing.app_error", "translation": "Command does not exist." }, - { - "id": "store.sql_group.app_error", - "translation": "failed to build query." - }, - { - "id": "store.sql_group.group_syncable_already_deleted", - "translation": "group syncable was already deleted" - }, - { - "id": "store.sql_group.more_than_one_row_changed", - "translation": "More than one row changed." - }, - { - "id": "store.sql_group.no_rows", - "translation": "no matching group found" - }, - { - "id": "store.sql_group.permanent_delete_members_by_user.app_error", - "translation": "Unable to remove the group member with UserID \"{{.UserId}}\"." - }, - { - "id": "store.sql_group.unique_constraint", - "translation": "a group with that name already exists" - }, - { - "id": "store.sql_group.uniqueness_error", - "translation": "group member already exists" - }, { "id": "store.sql_post.search.disabled", "translation": "Searching has been disabled on this server. Please contact your System Administrator." @@ -8174,10 +8154,6 @@ "id": "store.sql_user.update.email_taken.app_error", "translation": "This email is already taken. Please choose another." }, - { - "id": "store.update_error", - "translation": "update error" - }, { "id": "system.message.name", "translation": "System" diff --git a/model/group.go b/model/group.go index 2eda118467..49783c83da 100644 --- a/model/group.go +++ b/model/group.go @@ -157,7 +157,7 @@ func (group *Group) requiresRemoteId() bool { func (group *Group) IsValidForUpdate() *AppError { if !IsValidId(group.Id) { - return NewAppError("Group.IsValidForUpdate", "model.group.id.app_error", nil, "", http.StatusBadRequest) + return NewAppError("Group.IsValidForUpdate", "app.group.id.app_error", nil, "", http.StatusBadRequest) } if group.CreateAt == 0 { return NewAppError("Group.IsValidForUpdate", "model.group.create_at.app_error", nil, "", http.StatusBadRequest) diff --git a/store/opentracinglayer/opentracinglayer.go b/store/opentracinglayer/opentracinglayer.go index 1463d68b32..ad60a41a4d 100644 --- a/store/opentracinglayer/opentracinglayer.go +++ b/store/opentracinglayer/opentracinglayer.go @@ -3175,7 +3175,7 @@ func (s *OpenTracingLayerFileInfoStore) Upsert(info *model.FileInfo) (*model.Fil return result, err } -func (s *OpenTracingLayerGroupStore) AdminRoleGroupsForSyncableMember(userID string, syncableID string, syncableType model.GroupSyncableType) ([]string, *model.AppError) { +func (s *OpenTracingLayerGroupStore) AdminRoleGroupsForSyncableMember(userID string, syncableID string, syncableType model.GroupSyncableType) ([]string, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.AdminRoleGroupsForSyncableMember") s.Root.Store.SetContext(newCtx) @@ -3193,7 +3193,7 @@ func (s *OpenTracingLayerGroupStore) AdminRoleGroupsForSyncableMember(userID str return result, err } -func (s *OpenTracingLayerGroupStore) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, *model.AppError) { +func (s *OpenTracingLayerGroupStore) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.ChannelMembersMinusGroupMembers") s.Root.Store.SetContext(newCtx) @@ -3211,7 +3211,7 @@ func (s *OpenTracingLayerGroupStore) ChannelMembersMinusGroupMembers(channelID s return result, err } -func (s *OpenTracingLayerGroupStore) ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, *model.AppError) { +func (s *OpenTracingLayerGroupStore) ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.ChannelMembersToAdd") s.Root.Store.SetContext(newCtx) @@ -3229,7 +3229,7 @@ func (s *OpenTracingLayerGroupStore) ChannelMembersToAdd(since int64, channelID return result, err } -func (s *OpenTracingLayerGroupStore) ChannelMembersToRemove(channelID *string) ([]*model.ChannelMember, *model.AppError) { +func (s *OpenTracingLayerGroupStore) ChannelMembersToRemove(channelID *string) ([]*model.ChannelMember, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.ChannelMembersToRemove") s.Root.Store.SetContext(newCtx) @@ -3247,7 +3247,7 @@ func (s *OpenTracingLayerGroupStore) ChannelMembersToRemove(channelID *string) ( return result, err } -func (s *OpenTracingLayerGroupStore) CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, *model.AppError) { +func (s *OpenTracingLayerGroupStore) CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.CountChannelMembersMinusGroupMembers") s.Root.Store.SetContext(newCtx) @@ -3265,7 +3265,7 @@ func (s *OpenTracingLayerGroupStore) CountChannelMembersMinusGroupMembers(channe return result, err } -func (s *OpenTracingLayerGroupStore) CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, *model.AppError) { +func (s *OpenTracingLayerGroupStore) CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.CountGroupsByChannel") s.Root.Store.SetContext(newCtx) @@ -3283,7 +3283,7 @@ func (s *OpenTracingLayerGroupStore) CountGroupsByChannel(channelId string, opts return result, err } -func (s *OpenTracingLayerGroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, *model.AppError) { +func (s *OpenTracingLayerGroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.CountGroupsByTeam") s.Root.Store.SetContext(newCtx) @@ -3301,7 +3301,7 @@ func (s *OpenTracingLayerGroupStore) CountGroupsByTeam(teamId string, opts model return result, err } -func (s *OpenTracingLayerGroupStore) CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, *model.AppError) { +func (s *OpenTracingLayerGroupStore) CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.CountTeamMembersMinusGroupMembers") s.Root.Store.SetContext(newCtx) @@ -3319,7 +3319,7 @@ func (s *OpenTracingLayerGroupStore) CountTeamMembersMinusGroupMembers(teamID st return result, err } -func (s *OpenTracingLayerGroupStore) Create(group *model.Group) (*model.Group, *model.AppError) { +func (s *OpenTracingLayerGroupStore) Create(group *model.Group) (*model.Group, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.Create") s.Root.Store.SetContext(newCtx) @@ -3337,7 +3337,7 @@ func (s *OpenTracingLayerGroupStore) Create(group *model.Group) (*model.Group, * return result, err } -func (s *OpenTracingLayerGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) { +func (s *OpenTracingLayerGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.CreateGroupSyncable") s.Root.Store.SetContext(newCtx) @@ -3355,7 +3355,7 @@ func (s *OpenTracingLayerGroupStore) CreateGroupSyncable(groupSyncable *model.Gr return result, err } -func (s *OpenTracingLayerGroupStore) Delete(groupID string) (*model.Group, *model.AppError) { +func (s *OpenTracingLayerGroupStore) Delete(groupID string) (*model.Group, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.Delete") s.Root.Store.SetContext(newCtx) @@ -3373,7 +3373,7 @@ func (s *OpenTracingLayerGroupStore) Delete(groupID string) (*model.Group, *mode return result, err } -func (s *OpenTracingLayerGroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) { +func (s *OpenTracingLayerGroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.DeleteGroupSyncable") s.Root.Store.SetContext(newCtx) @@ -3391,7 +3391,7 @@ func (s *OpenTracingLayerGroupStore) DeleteGroupSyncable(groupID string, syncabl return result, err } -func (s *OpenTracingLayerGroupStore) DeleteMember(groupID string, userID string) (*model.GroupMember, *model.AppError) { +func (s *OpenTracingLayerGroupStore) DeleteMember(groupID string, userID string) (*model.GroupMember, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.DeleteMember") s.Root.Store.SetContext(newCtx) @@ -3409,7 +3409,7 @@ func (s *OpenTracingLayerGroupStore) DeleteMember(groupID string, userID string) return result, err } -func (s *OpenTracingLayerGroupStore) DistinctGroupMemberCount() (int64, *model.AppError) { +func (s *OpenTracingLayerGroupStore) DistinctGroupMemberCount() (int64, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.DistinctGroupMemberCount") s.Root.Store.SetContext(newCtx) @@ -3427,7 +3427,7 @@ func (s *OpenTracingLayerGroupStore) DistinctGroupMemberCount() (int64, *model.A return result, err } -func (s *OpenTracingLayerGroupStore) Get(groupID string) (*model.Group, *model.AppError) { +func (s *OpenTracingLayerGroupStore) Get(groupID string) (*model.Group, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.Get") s.Root.Store.SetContext(newCtx) @@ -3445,7 +3445,7 @@ func (s *OpenTracingLayerGroupStore) Get(groupID string) (*model.Group, *model.A return result, err } -func (s *OpenTracingLayerGroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.Group, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetAllBySource") s.Root.Store.SetContext(newCtx) @@ -3463,7 +3463,7 @@ func (s *OpenTracingLayerGroupStore) GetAllBySource(groupSource model.GroupSourc return result, err } -func (s *OpenTracingLayerGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetAllGroupSyncablesByGroupId") s.Root.Store.SetContext(newCtx) @@ -3481,7 +3481,7 @@ func (s *OpenTracingLayerGroupStore) GetAllGroupSyncablesByGroupId(groupID strin return result, err } -func (s *OpenTracingLayerGroupStore) GetByIDs(groupIDs []string) ([]*model.Group, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetByIDs(groupIDs []string) ([]*model.Group, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetByIDs") s.Root.Store.SetContext(newCtx) @@ -3499,7 +3499,7 @@ func (s *OpenTracingLayerGroupStore) GetByIDs(groupIDs []string) ([]*model.Group return result, err } -func (s *OpenTracingLayerGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetByName") s.Root.Store.SetContext(newCtx) @@ -3517,7 +3517,7 @@ func (s *OpenTracingLayerGroupStore) GetByName(name string, opts model.GroupSear return result, err } -func (s *OpenTracingLayerGroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetByRemoteID") s.Root.Store.SetContext(newCtx) @@ -3535,7 +3535,7 @@ func (s *OpenTracingLayerGroupStore) GetByRemoteID(remoteID string, groupSource return result, err } -func (s *OpenTracingLayerGroupStore) GetByUser(userId string) ([]*model.Group, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetByUser(userId string) ([]*model.Group, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetByUser") s.Root.Store.SetContext(newCtx) @@ -3553,7 +3553,7 @@ func (s *OpenTracingLayerGroupStore) GetByUser(userId string) ([]*model.Group, * return result, err } -func (s *OpenTracingLayerGroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetGroupSyncable") s.Root.Store.SetContext(newCtx) @@ -3571,7 +3571,7 @@ func (s *OpenTracingLayerGroupStore) GetGroupSyncable(groupID string, syncableID return result, err } -func (s *OpenTracingLayerGroupStore) GetGroups(page int, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetGroups(page int, perPage int, opts model.GroupSearchOpts) ([]*model.Group, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetGroups") s.Root.Store.SetContext(newCtx) @@ -3589,7 +3589,7 @@ func (s *OpenTracingLayerGroupStore) GetGroups(page int, perPage int, opts model return result, err } -func (s *OpenTracingLayerGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetGroupsAssociatedToChannelsByTeam") s.Root.Store.SetContext(newCtx) @@ -3607,7 +3607,7 @@ func (s *OpenTracingLayerGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId return result, err } -func (s *OpenTracingLayerGroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetGroupsByChannel") s.Root.Store.SetContext(newCtx) @@ -3625,7 +3625,7 @@ func (s *OpenTracingLayerGroupStore) GetGroupsByChannel(channelId string, opts m return result, err } -func (s *OpenTracingLayerGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetGroupsByTeam") s.Root.Store.SetContext(newCtx) @@ -3643,7 +3643,7 @@ func (s *OpenTracingLayerGroupStore) GetGroupsByTeam(teamId string, opts model.G return result, err } -func (s *OpenTracingLayerGroupStore) GetMemberCount(groupID string) (int64, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetMemberCount(groupID string) (int64, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetMemberCount") s.Root.Store.SetContext(newCtx) @@ -3661,7 +3661,7 @@ func (s *OpenTracingLayerGroupStore) GetMemberCount(groupID string) (int64, *mod return result, err } -func (s *OpenTracingLayerGroupStore) GetMemberUsers(groupID string) ([]*model.User, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetMemberUsers(groupID string) ([]*model.User, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetMemberUsers") s.Root.Store.SetContext(newCtx) @@ -3679,7 +3679,7 @@ func (s *OpenTracingLayerGroupStore) GetMemberUsers(groupID string) ([]*model.Us return result, err } -func (s *OpenTracingLayerGroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]*model.User, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]*model.User, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetMemberUsersInTeam") s.Root.Store.SetContext(newCtx) @@ -3697,7 +3697,7 @@ func (s *OpenTracingLayerGroupStore) GetMemberUsersInTeam(groupID string, teamID return result, err } -func (s *OpenTracingLayerGroupStore) GetMemberUsersNotInChannel(groupID string, channelID string) ([]*model.User, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetMemberUsersNotInChannel(groupID string, channelID string) ([]*model.User, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetMemberUsersNotInChannel") s.Root.Store.SetContext(newCtx) @@ -3715,7 +3715,7 @@ func (s *OpenTracingLayerGroupStore) GetMemberUsersNotInChannel(groupID string, return result, err } -func (s *OpenTracingLayerGroupStore) GetMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GetMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetMemberUsersPage") s.Root.Store.SetContext(newCtx) @@ -3733,7 +3733,7 @@ func (s *OpenTracingLayerGroupStore) GetMemberUsersPage(groupID string, page int return result, err } -func (s *OpenTracingLayerGroupStore) GroupChannelCount() (int64, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GroupChannelCount() (int64, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GroupChannelCount") s.Root.Store.SetContext(newCtx) @@ -3751,7 +3751,7 @@ func (s *OpenTracingLayerGroupStore) GroupChannelCount() (int64, *model.AppError return result, err } -func (s *OpenTracingLayerGroupStore) GroupCount() (int64, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GroupCount() (int64, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GroupCount") s.Root.Store.SetContext(newCtx) @@ -3769,7 +3769,7 @@ func (s *OpenTracingLayerGroupStore) GroupCount() (int64, *model.AppError) { return result, err } -func (s *OpenTracingLayerGroupStore) GroupCountWithAllowReference() (int64, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GroupCountWithAllowReference() (int64, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GroupCountWithAllowReference") s.Root.Store.SetContext(newCtx) @@ -3787,7 +3787,7 @@ func (s *OpenTracingLayerGroupStore) GroupCountWithAllowReference() (int64, *mod return result, err } -func (s *OpenTracingLayerGroupStore) GroupMemberCount() (int64, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GroupMemberCount() (int64, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GroupMemberCount") s.Root.Store.SetContext(newCtx) @@ -3805,7 +3805,7 @@ func (s *OpenTracingLayerGroupStore) GroupMemberCount() (int64, *model.AppError) return result, err } -func (s *OpenTracingLayerGroupStore) GroupTeamCount() (int64, *model.AppError) { +func (s *OpenTracingLayerGroupStore) GroupTeamCount() (int64, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GroupTeamCount") s.Root.Store.SetContext(newCtx) @@ -3823,7 +3823,7 @@ func (s *OpenTracingLayerGroupStore) GroupTeamCount() (int64, *model.AppError) { return result, err } -func (s *OpenTracingLayerGroupStore) PermanentDeleteMembersByUser(userId string) *model.AppError { +func (s *OpenTracingLayerGroupStore) PermanentDeleteMembersByUser(userId string) error { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.PermanentDeleteMembersByUser") s.Root.Store.SetContext(newCtx) @@ -3841,7 +3841,7 @@ func (s *OpenTracingLayerGroupStore) PermanentDeleteMembersByUser(userId string) return err } -func (s *OpenTracingLayerGroupStore) PermittedSyncableAdmins(syncableID string, syncableType model.GroupSyncableType) ([]string, *model.AppError) { +func (s *OpenTracingLayerGroupStore) PermittedSyncableAdmins(syncableID string, syncableType model.GroupSyncableType) ([]string, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.PermittedSyncableAdmins") s.Root.Store.SetContext(newCtx) @@ -3859,7 +3859,7 @@ func (s *OpenTracingLayerGroupStore) PermittedSyncableAdmins(syncableID string, return result, err } -func (s *OpenTracingLayerGroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, *model.AppError) { +func (s *OpenTracingLayerGroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.TeamMembersMinusGroupMembers") s.Root.Store.SetContext(newCtx) @@ -3877,7 +3877,7 @@ func (s *OpenTracingLayerGroupStore) TeamMembersMinusGroupMembers(teamID string, return result, err } -func (s *OpenTracingLayerGroupStore) TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, *model.AppError) { +func (s *OpenTracingLayerGroupStore) TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.TeamMembersToAdd") s.Root.Store.SetContext(newCtx) @@ -3895,7 +3895,7 @@ func (s *OpenTracingLayerGroupStore) TeamMembersToAdd(since int64, teamID *strin return result, err } -func (s *OpenTracingLayerGroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError) { +func (s *OpenTracingLayerGroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.TeamMembersToRemove") s.Root.Store.SetContext(newCtx) @@ -3913,7 +3913,7 @@ func (s *OpenTracingLayerGroupStore) TeamMembersToRemove(teamID *string) ([]*mod return result, err } -func (s *OpenTracingLayerGroupStore) Update(group *model.Group) (*model.Group, *model.AppError) { +func (s *OpenTracingLayerGroupStore) Update(group *model.Group) (*model.Group, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.Update") s.Root.Store.SetContext(newCtx) @@ -3931,7 +3931,7 @@ func (s *OpenTracingLayerGroupStore) Update(group *model.Group) (*model.Group, * return result, err } -func (s *OpenTracingLayerGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) { +func (s *OpenTracingLayerGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.UpdateGroupSyncable") s.Root.Store.SetContext(newCtx) @@ -3949,7 +3949,7 @@ func (s *OpenTracingLayerGroupStore) UpdateGroupSyncable(groupSyncable *model.Gr return result, err } -func (s *OpenTracingLayerGroupStore) UpsertMember(groupID string, userID string) (*model.GroupMember, *model.AppError) { +func (s *OpenTracingLayerGroupStore) UpsertMember(groupID string, userID string) (*model.GroupMember, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.UpsertMember") s.Root.Store.SetContext(newCtx) diff --git a/store/retrylayer/retrylayer.go b/store/retrylayer/retrylayer.go index 013ad0d3e2..a566dbd9ed 100644 --- a/store/retrylayer/retrylayer.go +++ b/store/retrylayer/retrylayer.go @@ -3396,267 +3396,883 @@ func (s *RetryLayerFileInfoStore) Upsert(info *model.FileInfo) (*model.FileInfo, } -func (s *RetryLayerGroupStore) AdminRoleGroupsForSyncableMember(userID string, syncableID string, syncableType model.GroupSyncableType) ([]string, *model.AppError) { +func (s *RetryLayerGroupStore) AdminRoleGroupsForSyncableMember(userID string, syncableID string, syncableType model.GroupSyncableType) ([]string, error) { - return s.GroupStore.AdminRoleGroupsForSyncableMember(userID, syncableID, syncableType) + tries := 0 + for { + result, err := s.GroupStore.AdminRoleGroupsForSyncableMember(userID, syncableID, syncableType) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, *model.AppError) { +func (s *RetryLayerGroupStore) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, error) { - return s.GroupStore.ChannelMembersMinusGroupMembers(channelID, groupIDs, page, perPage) + tries := 0 + for { + result, err := s.GroupStore.ChannelMembersMinusGroupMembers(channelID, groupIDs, page, perPage) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, *model.AppError) { +func (s *RetryLayerGroupStore) ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, error) { - return s.GroupStore.ChannelMembersToAdd(since, channelID) + tries := 0 + for { + result, err := s.GroupStore.ChannelMembersToAdd(since, channelID) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) ChannelMembersToRemove(channelID *string) ([]*model.ChannelMember, *model.AppError) { +func (s *RetryLayerGroupStore) ChannelMembersToRemove(channelID *string) ([]*model.ChannelMember, error) { - return s.GroupStore.ChannelMembersToRemove(channelID) + tries := 0 + for { + result, err := s.GroupStore.ChannelMembersToRemove(channelID) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, *model.AppError) { +func (s *RetryLayerGroupStore) CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, error) { - return s.GroupStore.CountChannelMembersMinusGroupMembers(channelID, groupIDs) + tries := 0 + for { + result, err := s.GroupStore.CountChannelMembersMinusGroupMembers(channelID, groupIDs) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, *model.AppError) { +func (s *RetryLayerGroupStore) CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, error) { - return s.GroupStore.CountGroupsByChannel(channelId, opts) + tries := 0 + for { + result, err := s.GroupStore.CountGroupsByChannel(channelId, opts) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, *model.AppError) { +func (s *RetryLayerGroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, error) { - return s.GroupStore.CountGroupsByTeam(teamId, opts) + tries := 0 + for { + result, err := s.GroupStore.CountGroupsByTeam(teamId, opts) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, *model.AppError) { +func (s *RetryLayerGroupStore) CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, error) { - return s.GroupStore.CountTeamMembersMinusGroupMembers(teamID, groupIDs) + tries := 0 + for { + result, err := s.GroupStore.CountTeamMembersMinusGroupMembers(teamID, groupIDs) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) Create(group *model.Group) (*model.Group, *model.AppError) { +func (s *RetryLayerGroupStore) Create(group *model.Group) (*model.Group, error) { - return s.GroupStore.Create(group) + tries := 0 + for { + result, err := s.GroupStore.Create(group) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) { +func (s *RetryLayerGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, error) { - return s.GroupStore.CreateGroupSyncable(groupSyncable) + tries := 0 + for { + result, err := s.GroupStore.CreateGroupSyncable(groupSyncable) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) Delete(groupID string) (*model.Group, *model.AppError) { +func (s *RetryLayerGroupStore) Delete(groupID string) (*model.Group, error) { - return s.GroupStore.Delete(groupID) + tries := 0 + for { + result, err := s.GroupStore.Delete(groupID) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) { +func (s *RetryLayerGroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) { - return s.GroupStore.DeleteGroupSyncable(groupID, syncableID, syncableType) + tries := 0 + for { + result, err := s.GroupStore.DeleteGroupSyncable(groupID, syncableID, syncableType) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) DeleteMember(groupID string, userID string) (*model.GroupMember, *model.AppError) { +func (s *RetryLayerGroupStore) DeleteMember(groupID string, userID string) (*model.GroupMember, error) { - return s.GroupStore.DeleteMember(groupID, userID) + tries := 0 + for { + result, err := s.GroupStore.DeleteMember(groupID, userID) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) DistinctGroupMemberCount() (int64, *model.AppError) { +func (s *RetryLayerGroupStore) DistinctGroupMemberCount() (int64, error) { - return s.GroupStore.DistinctGroupMemberCount() + tries := 0 + for { + result, err := s.GroupStore.DistinctGroupMemberCount() + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) Get(groupID string) (*model.Group, *model.AppError) { +func (s *RetryLayerGroupStore) Get(groupID string) (*model.Group, error) { - return s.GroupStore.Get(groupID) + tries := 0 + for { + result, err := s.GroupStore.Get(groupID) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) { +func (s *RetryLayerGroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.Group, error) { - return s.GroupStore.GetAllBySource(groupSource) + tries := 0 + for { + result, err := s.GroupStore.GetAllBySource(groupSource) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) { +func (s *RetryLayerGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, error) { - return s.GroupStore.GetAllGroupSyncablesByGroupId(groupID, syncableType) + tries := 0 + for { + result, err := s.GroupStore.GetAllGroupSyncablesByGroupId(groupID, syncableType) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetByIDs(groupIDs []string) ([]*model.Group, *model.AppError) { +func (s *RetryLayerGroupStore) GetByIDs(groupIDs []string) ([]*model.Group, error) { - return s.GroupStore.GetByIDs(groupIDs) + tries := 0 + for { + result, err := s.GroupStore.GetByIDs(groupIDs) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError) { +func (s *RetryLayerGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, error) { - return s.GroupStore.GetByName(name, opts) + tries := 0 + for { + result, err := s.GroupStore.GetByName(name, opts) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError) { +func (s *RetryLayerGroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, error) { - return s.GroupStore.GetByRemoteID(remoteID, groupSource) + tries := 0 + for { + result, err := s.GroupStore.GetByRemoteID(remoteID, groupSource) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetByUser(userId string) ([]*model.Group, *model.AppError) { +func (s *RetryLayerGroupStore) GetByUser(userId string) ([]*model.Group, error) { - return s.GroupStore.GetByUser(userId) + tries := 0 + for { + result, err := s.GroupStore.GetByUser(userId) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) { +func (s *RetryLayerGroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) { - return s.GroupStore.GetGroupSyncable(groupID, syncableID, syncableType) + tries := 0 + for { + result, err := s.GroupStore.GetGroupSyncable(groupID, syncableID, syncableType) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetGroups(page int, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) { +func (s *RetryLayerGroupStore) GetGroups(page int, perPage int, opts model.GroupSearchOpts) ([]*model.Group, error) { - return s.GroupStore.GetGroups(page, perPage, opts) + tries := 0 + for { + result, err := s.GroupStore.GetGroups(page, perPage, opts) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError) { +func (s *RetryLayerGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, error) { - return s.GroupStore.GetGroupsAssociatedToChannelsByTeam(teamId, opts) + tries := 0 + for { + result, err := s.GroupStore.GetGroupsAssociatedToChannelsByTeam(teamId, opts) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) { +func (s *RetryLayerGroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, error) { - return s.GroupStore.GetGroupsByChannel(channelId, opts) + tries := 0 + for { + result, err := s.GroupStore.GetGroupsByChannel(channelId, opts) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) { +func (s *RetryLayerGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, error) { - return s.GroupStore.GetGroupsByTeam(teamId, opts) + tries := 0 + for { + result, err := s.GroupStore.GetGroupsByTeam(teamId, opts) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetMemberCount(groupID string) (int64, *model.AppError) { +func (s *RetryLayerGroupStore) GetMemberCount(groupID string) (int64, error) { - return s.GroupStore.GetMemberCount(groupID) + tries := 0 + for { + result, err := s.GroupStore.GetMemberCount(groupID) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetMemberUsers(groupID string) ([]*model.User, *model.AppError) { +func (s *RetryLayerGroupStore) GetMemberUsers(groupID string) ([]*model.User, error) { - return s.GroupStore.GetMemberUsers(groupID) + tries := 0 + for { + result, err := s.GroupStore.GetMemberUsers(groupID) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]*model.User, *model.AppError) { +func (s *RetryLayerGroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]*model.User, error) { - return s.GroupStore.GetMemberUsersInTeam(groupID, teamID) + tries := 0 + for { + result, err := s.GroupStore.GetMemberUsersInTeam(groupID, teamID) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetMemberUsersNotInChannel(groupID string, channelID string) ([]*model.User, *model.AppError) { +func (s *RetryLayerGroupStore) GetMemberUsersNotInChannel(groupID string, channelID string) ([]*model.User, error) { - return s.GroupStore.GetMemberUsersNotInChannel(groupID, channelID) + tries := 0 + for { + result, err := s.GroupStore.GetMemberUsersNotInChannel(groupID, channelID) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GetMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, *model.AppError) { +func (s *RetryLayerGroupStore) GetMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, error) { - return s.GroupStore.GetMemberUsersPage(groupID, page, perPage) + tries := 0 + for { + result, err := s.GroupStore.GetMemberUsersPage(groupID, page, perPage) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GroupChannelCount() (int64, *model.AppError) { +func (s *RetryLayerGroupStore) GroupChannelCount() (int64, error) { - return s.GroupStore.GroupChannelCount() + tries := 0 + for { + result, err := s.GroupStore.GroupChannelCount() + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GroupCount() (int64, *model.AppError) { +func (s *RetryLayerGroupStore) GroupCount() (int64, error) { - return s.GroupStore.GroupCount() + tries := 0 + for { + result, err := s.GroupStore.GroupCount() + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GroupCountWithAllowReference() (int64, *model.AppError) { +func (s *RetryLayerGroupStore) GroupCountWithAllowReference() (int64, error) { - return s.GroupStore.GroupCountWithAllowReference() + tries := 0 + for { + result, err := s.GroupStore.GroupCountWithAllowReference() + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GroupMemberCount() (int64, *model.AppError) { +func (s *RetryLayerGroupStore) GroupMemberCount() (int64, error) { - return s.GroupStore.GroupMemberCount() + tries := 0 + for { + result, err := s.GroupStore.GroupMemberCount() + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) GroupTeamCount() (int64, *model.AppError) { +func (s *RetryLayerGroupStore) GroupTeamCount() (int64, error) { - return s.GroupStore.GroupTeamCount() + tries := 0 + for { + result, err := s.GroupStore.GroupTeamCount() + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) PermanentDeleteMembersByUser(userId string) *model.AppError { +func (s *RetryLayerGroupStore) PermanentDeleteMembersByUser(userId string) error { - return s.GroupStore.PermanentDeleteMembersByUser(userId) + tries := 0 + for { + err := s.GroupStore.PermanentDeleteMembersByUser(userId) + if err == nil { + return nil + } + if !isRepeatableError(err) { + return err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return err + } + } } -func (s *RetryLayerGroupStore) PermittedSyncableAdmins(syncableID string, syncableType model.GroupSyncableType) ([]string, *model.AppError) { +func (s *RetryLayerGroupStore) PermittedSyncableAdmins(syncableID string, syncableType model.GroupSyncableType) ([]string, error) { - return s.GroupStore.PermittedSyncableAdmins(syncableID, syncableType) + tries := 0 + for { + result, err := s.GroupStore.PermittedSyncableAdmins(syncableID, syncableType) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, *model.AppError) { +func (s *RetryLayerGroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, error) { - return s.GroupStore.TeamMembersMinusGroupMembers(teamID, groupIDs, page, perPage) + tries := 0 + for { + result, err := s.GroupStore.TeamMembersMinusGroupMembers(teamID, groupIDs, page, perPage) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, *model.AppError) { +func (s *RetryLayerGroupStore) TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, error) { - return s.GroupStore.TeamMembersToAdd(since, teamID) + tries := 0 + for { + result, err := s.GroupStore.TeamMembersToAdd(since, teamID) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError) { +func (s *RetryLayerGroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, error) { - return s.GroupStore.TeamMembersToRemove(teamID) + tries := 0 + for { + result, err := s.GroupStore.TeamMembersToRemove(teamID) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) Update(group *model.Group) (*model.Group, *model.AppError) { +func (s *RetryLayerGroupStore) Update(group *model.Group) (*model.Group, error) { - return s.GroupStore.Update(group) + tries := 0 + for { + result, err := s.GroupStore.Update(group) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) { +func (s *RetryLayerGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, error) { - return s.GroupStore.UpdateGroupSyncable(groupSyncable) + tries := 0 + for { + result, err := s.GroupStore.UpdateGroupSyncable(groupSyncable) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } -func (s *RetryLayerGroupStore) UpsertMember(groupID string, userID string) (*model.GroupMember, *model.AppError) { +func (s *RetryLayerGroupStore) UpsertMember(groupID string, userID string) (*model.GroupMember, error) { - return s.GroupStore.UpsertMember(groupID, userID) + tries := 0 + for { + result, err := s.GroupStore.UpsertMember(groupID, userID) + if err == nil { + return result, nil + } + if !isRepeatableError(err) { + return result, err + } + tries++ + if tries >= 3 { + err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") + return result, err + } + } } diff --git a/store/sqlstore/group_store.go b/store/sqlstore/group_store.go index 4db424ddfa..e1dc14ef7a 100644 --- a/store/sqlstore/group_store.go +++ b/store/sqlstore/group_store.go @@ -6,7 +6,6 @@ package sqlstore import ( "database/sql" "fmt" - "net/http" "strings" sq "github.com/Masterminds/squirrel" @@ -91,9 +90,9 @@ func (s *SqlGroupStore) createIndexesIfNotExists() { s.CreateIndexIfNotExists("idx_groupchannels_schemeadmin", "GroupChannels", "SchemeAdmin") } -func (s *SqlGroupStore) Create(group *model.Group) (*model.Group, *model.AppError) { +func (s *SqlGroupStore) Create(group *model.Group) (*model.Group, error) { if len(group.Id) != 0 { - return nil, model.NewAppError("SqlGroupStore.GroupCreate", "model.group.id.app_error", nil, "", http.StatusBadRequest) + return nil, store.NewErrInvalidInput("Group", "id", group.Id) } if err := group.IsValidForCreate(); err != nil { @@ -106,27 +105,27 @@ func (s *SqlGroupStore) Create(group *model.Group) (*model.Group, *model.AppErro if err := s.GetMaster().Insert(group); err != nil { if IsUniqueConstraintError(err, []string{"Name", "groups_name_key"}) { - return nil, model.NewAppError("SqlGroupStore.GroupCreate", "store.sql_group.unique_constraint", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "Group with name %s already exists", *group.Name) } - return nil, model.NewAppError("SqlGroupStore.GroupCreate", "store.insert_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to save Group") } return group, nil } -func (s *SqlGroupStore) Get(groupId string) (*model.Group, *model.AppError) { +func (s *SqlGroupStore) Get(groupId string) (*model.Group, error) { var group *model.Group if err := s.GetReplica().SelectOne(&group, "SELECT * from UserGroups WHERE Id = :Id", map[string]interface{}{"Id": groupId}); err != nil { if err == sql.ErrNoRows { - return nil, model.NewAppError("SqlGroupStore.GroupGet", "store.sql_group.no_rows", nil, err.Error(), http.StatusNotFound) + return nil, store.NewErrNotFound("Group", groupId) } - return nil, model.NewAppError("SqlGroupStore.GroupGet", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get Group with id=%s", groupId) } return group, nil } -func (s *SqlGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError) { +func (s *SqlGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, error) { var group *model.Group query := s.getQueryBuilder().Select("*").From("UserGroups").Where(sq.Eq{"Name": name}) if opts.FilterAllowReference { @@ -136,54 +135,54 @@ func (s *SqlGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*mod queryString, args, err := query.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.GetByName", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "get_by_name_tosql") } if err := s.GetReplica().SelectOne(&group, queryString, args...); err != nil { if err == sql.ErrNoRows { - return nil, model.NewAppError("SqlGroupStore.GroupGetByName", "store.sql_group.no_rows", nil, err.Error(), http.StatusNotFound) + return nil, store.NewErrNotFound("Group", fmt.Sprintf("name=%s", name)) } - return nil, model.NewAppError("SqlGroupStore.GroupGetByName", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get Group with name=%s", name) } return group, nil } -func (s *SqlGroupStore) GetByIDs(groupIDs []string) ([]*model.Group, *model.AppError) { +func (s *SqlGroupStore) GetByIDs(groupIDs []string) ([]*model.Group, error) { var groups []*model.Group query := s.getQueryBuilder().Select("*").From("UserGroups").Where(sq.Eq{"Id": groupIDs}) queryString, args, err := query.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.GetByIDs", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "get_by_ids_tosql") } if _, err := s.GetReplica().Select(&groups, queryString, args...); err != nil { - return nil, model.NewAppError("SqlGroupStore.GetByIDs", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to find Groups by ids") } return groups, nil } -func (s *SqlGroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError) { +func (s *SqlGroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, error) { var group *model.Group if err := s.GetReplica().SelectOne(&group, "SELECT * from UserGroups WHERE RemoteId = :RemoteId AND Source = :Source", map[string]interface{}{"RemoteId": remoteID, "Source": groupSource}); err != nil { if err == sql.ErrNoRows { - return nil, model.NewAppError("SqlGroupStore.GroupGetByRemoteID", "store.sql_group.no_rows", nil, err.Error(), http.StatusNotFound) + return nil, store.NewErrNotFound("Group", fmt.Sprintf("remoteId=%s", remoteID)) } - return nil, model.NewAppError("SqlGroupStore.GroupGetByRemoteID", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get Group with remoteId=%s", remoteID) } return group, nil } -func (s *SqlGroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) { +func (s *SqlGroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.Group, error) { var groups []*model.Group if _, err := s.GetReplica().Select(&groups, "SELECT * from UserGroups WHERE DeleteAt = 0 AND Source = :Source", map[string]interface{}{"Source": groupSource}); err != nil { - return nil, model.NewAppError("SqlGroupStore.GroupGetAllBySource", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find Groups by groupSource=%v", groupSource) } return groups, nil } -func (s *SqlGroupStore) GetByUser(userId string) ([]*model.Group, *model.AppError) { +func (s *SqlGroupStore) GetByUser(userId string) ([]*model.Group, error) { var groups []*model.Group query := ` @@ -197,24 +196,24 @@ func (s *SqlGroupStore) GetByUser(userId string) ([]*model.Group, *model.AppErro AND UserId = :UserId` if _, err := s.GetReplica().Select(&groups, query, map[string]interface{}{"UserId": userId}); err != nil { - return nil, model.NewAppError("SqlGroupStore.GetByUser", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find Groups with userId=%s", userId) } return groups, nil } -func (s *SqlGroupStore) Update(group *model.Group) (*model.Group, *model.AppError) { +func (s *SqlGroupStore) Update(group *model.Group) (*model.Group, error) { var retrievedGroup *model.Group if err := s.GetReplica().SelectOne(&retrievedGroup, "SELECT * FROM UserGroups WHERE Id = :Id", map[string]interface{}{"Id": group.Id}); err != nil { if err == sql.ErrNoRows { - return nil, model.NewAppError("SqlGroupStore.GroupUpdate", "store.sql_group.no_rows", nil, "id="+group.Id+","+err.Error(), http.StatusNotFound) + return nil, store.NewErrNotFound("Group", group.Id) } - return nil, model.NewAppError("SqlGroupStore.GroupUpdate", "store.select_error", nil, "id="+group.Id+","+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get Group with id=%s", group.Id) } // If updating DeleteAt it can only be to 0 if group.DeleteAt != retrievedGroup.DeleteAt && group.DeleteAt != 0 { - return nil, model.NewAppError("SqlGroupStore.GroupUpdate", "model.group.delete_at.app_error", nil, "", http.StatusInternalServerError) + return nil, errors.New("DeleteAt should be 0 when updating") } // Reset these properties, don't update them based on input @@ -228,24 +227,24 @@ func (s *SqlGroupStore) Update(group *model.Group) (*model.Group, *model.AppErro rowsChanged, err := s.GetMaster().Update(group) if err != nil { if IsUniqueConstraintError(err, []string{"Name", "groups_name_key"}) { - return nil, model.NewAppError("SqlGroupStore.GroupUpdate", "store.sql_group.unique_constraint", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "Group with name %s already exists", *group.Name) } - return nil, model.NewAppError("SqlGroupStore.GroupUpdate", "store.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to update Group") } if rowsChanged > 1 { - return nil, model.NewAppError("SqlGroupStore.GroupUpdate", "store.sql_group.more_than_one_row_changed", nil, "", http.StatusInternalServerError) + return nil, errors.Wrapf(err, "multiple Groups were update: %d", rowsChanged) } return group, nil } -func (s *SqlGroupStore) Delete(groupID string) (*model.Group, *model.AppError) { +func (s *SqlGroupStore) Delete(groupID string) (*model.Group, error) { var group *model.Group if err := s.GetReplica().SelectOne(&group, "SELECT * from UserGroups WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": groupID}); err != nil { if err == sql.ErrNoRows { - return nil, model.NewAppError("SqlGroupStore.GroupDelete", "store.sql_group.no_rows", nil, "Id="+groupID+", "+err.Error(), http.StatusNotFound) + return nil, store.NewErrNotFound("Group", groupID) } - return nil, model.NewAppError("SqlGroupStore.GroupDelete", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get Group with id=%s", groupID) } time := model.GetMillis() @@ -253,13 +252,13 @@ func (s *SqlGroupStore) Delete(groupID string) (*model.Group, *model.AppError) { group.UpdateAt = time if _, err := s.GetMaster().Update(group); err != nil { - return nil, model.NewAppError("SqlGroupStore.GroupDelete", "store.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to update Group with id=%s", groupID) } return group, nil } -func (s *SqlGroupStore) GetMemberUsers(groupID string) ([]*model.User, *model.AppError) { +func (s *SqlGroupStore) GetMemberUsers(groupID string) ([]*model.User, error) { var groupMembers []*model.User query := ` @@ -274,13 +273,13 @@ func (s *SqlGroupStore) GetMemberUsers(groupID string) ([]*model.User, *model.Ap AND GroupId = :GroupId` if _, err := s.GetReplica().Select(&groupMembers, query, map[string]interface{}{"GroupId": groupID}); err != nil { - return nil, model.NewAppError("SqlGroupStore.GetMemberUsers", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find member Users for Group with id=%s", groupID) } return groupMembers, nil } -func (s *SqlGroupStore) GetMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, *model.AppError) { +func (s *SqlGroupStore) GetMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, error) { var groupMembers []*model.User query := ` @@ -301,13 +300,13 @@ func (s *SqlGroupStore) GetMemberUsersPage(groupID string, page int, perPage int :Offset` if _, err := s.GetReplica().Select(&groupMembers, query, map[string]interface{}{"GroupId": groupID, "Limit": perPage, "Offset": page * perPage}); err != nil { - return nil, model.NewAppError("SqlGroupStore.GroupGetMemberUsersPage", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find member Users for Group with id=%s", groupID) } return groupMembers, nil } -func (s *SqlGroupStore) GetMemberCount(groupID string) (int64, *model.AppError) { +func (s *SqlGroupStore) GetMemberCount(groupID string) (int64, error) { query := ` SELECT count(*) @@ -320,13 +319,13 @@ func (s *SqlGroupStore) GetMemberCount(groupID string) (int64, *model.AppError) count, err := s.GetReplica().SelectInt(query, map[string]interface{}{"GroupId": groupID}) if err != nil { - return int64(0), model.NewAppError("SqlGroupStore.GroupGetMemberUsersPage", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return int64(0), errors.Wrapf(err, "failed to count member Users for Group with id=%s", groupID) } return count, nil } -func (s *SqlGroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]*model.User, *model.AppError) { +func (s *SqlGroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]*model.User, error) { var groupMembers []*model.User query := ` @@ -349,13 +348,13 @@ func (s *SqlGroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]* ` if _, err := s.GetReplica().Select(&groupMembers, query, map[string]interface{}{"GroupId": groupID, "TeamId": teamID}); err != nil { - return nil, model.NewAppError("SqlGroupStore.GetMemberUsersInTeam", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to member Users for groupId=%s and teamId=%s", groupID, teamID) } return groupMembers, nil } -func (s *SqlGroupStore) GetMemberUsersNotInChannel(groupID string, channelID string) ([]*model.User, *model.AppError) { +func (s *SqlGroupStore) GetMemberUsersNotInChannel(groupID string, channelID string) ([]*model.User, error) { var groupMembers []*model.User query := ` @@ -384,13 +383,13 @@ func (s *SqlGroupStore) GetMemberUsersNotInChannel(groupID string, channelID str ` if _, err := s.GetReplica().Select(&groupMembers, query, map[string]interface{}{"GroupId": groupID, "ChannelId": channelID}); err != nil { - return nil, model.NewAppError("SqlGroupStore.GetMemberUsersNotInChannel", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to member Users for groupId=%s and channelId!=%s", groupID, channelID) } return groupMembers, nil } -func (s *SqlGroupStore) UpsertMember(groupID string, userID string) (*model.GroupMember, *model.AppError) { +func (s *SqlGroupStore) UpsertMember(groupID string, userID string) (*model.GroupMember, error) { member := &model.GroupMember{ GroupId: groupID, UserId: userID, @@ -403,64 +402,64 @@ func (s *SqlGroupStore) UpsertMember(groupID string, userID string) (*model.Grou var retrievedGroup *model.Group if err := s.GetReplica().SelectOne(&retrievedGroup, "SELECT * FROM UserGroups WHERE Id = :Id", map[string]interface{}{"Id": groupID}); err != nil { - return nil, model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.insert_error", nil, "group_id="+member.GroupId+"user_id="+member.UserId+","+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get UserGroup with groupId=%s and userId=%s", groupID, userID) } var retrievedMember *model.GroupMember if err := s.GetReplica().SelectOne(&retrievedMember, "SELECT * FROM GroupMembers WHERE GroupId = :GroupId AND UserId = :UserId", map[string]interface{}{"GroupId": member.GroupId, "UserId": member.UserId}); err != nil { if err != sql.ErrNoRows { - return nil, model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.select_error", nil, "group_id="+member.GroupId+"user_id="+member.UserId+","+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get GroupMember with groupId=%s and userId=%s", groupID, userID) } } if retrievedMember == nil { if err := s.GetMaster().Insert(member); err != nil { if IsUniqueConstraintError(err, []string{"GroupId", "UserId", "groupmembers_pkey", "PRIMARY"}) { - return nil, model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.sql_group.uniqueness_error", nil, "group_id="+member.GroupId+", user_id="+member.UserId+", "+err.Error(), http.StatusBadRequest) + return nil, store.NewErrInvalidInput("Member", "", fmt.Sprintf("<%s, %s>", groupID, userID)) } - return nil, model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.insert_error", nil, "group_id="+member.GroupId+", user_id="+member.UserId+", "+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to save Member") } } else { member.DeleteAt = 0 var rowsChanged int64 var err error if rowsChanged, err = s.GetMaster().Update(member); err != nil { - return nil, model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.update_error", nil, "group_id="+member.GroupId+", user_id="+member.UserId+", "+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to update GroupMember with groupId=%s and userId=%s", groupID, userID) } if rowsChanged > 1 { - return nil, model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.sql_group.more_than_one_row_changed", nil, "", http.StatusInternalServerError) + return nil, errors.Wrapf(err, "multiple GroupMembers were updated: %d", rowsChanged) } } return member, nil } -func (s *SqlGroupStore) DeleteMember(groupID string, userID string) (*model.GroupMember, *model.AppError) { +func (s *SqlGroupStore) DeleteMember(groupID string, userID string) (*model.GroupMember, error) { var retrievedMember *model.GroupMember if err := s.GetReplica().SelectOne(&retrievedMember, "SELECT * FROM GroupMembers WHERE GroupId = :GroupId AND UserId = :UserId AND DeleteAt = 0", map[string]interface{}{"GroupId": groupID, "UserId": userID}); err != nil { if err == sql.ErrNoRows { - return nil, model.NewAppError("SqlGroupStore.GroupDeleteMember", "store.sql_group.no_rows", nil, "group_id="+groupID+"user_id="+userID+","+err.Error(), http.StatusNotFound) + return nil, store.NewErrNotFound("GroupMember", fmt.Sprintf("groupId=%s, userId=%s", groupID, userID)) } - return nil, model.NewAppError("SqlGroupStore.GroupDeleteMember", "store.select_error", nil, "group_id="+groupID+"user_id="+userID+","+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get GroupMember with groupId=%s and userId=%s", groupID, userID) } retrievedMember.DeleteAt = model.GetMillis() if _, err := s.GetMaster().Update(retrievedMember); err != nil { - return nil, model.NewAppError("SqlGroupStore.GroupDeleteMember", "store.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to update GroupMember with groupId=%s and userId=%s", groupID, userID) } return retrievedMember, nil } -func (s *SqlGroupStore) PermanentDeleteMembersByUser(userId string) *model.AppError { +func (s *SqlGroupStore) PermanentDeleteMembersByUser(userId string) error { if _, err := s.GetMaster().Exec("DELETE FROM GroupMembers WHERE UserId = :UserId", map[string]interface{}{"UserId": userId}); err != nil { - return model.NewAppError("SqlGroupStore.GroupPermanentDeleteMembersByUser", "store.sql_group.permanent_delete_members_by_user.app_error", map[string]interface{}{"UserId": userId}, "", http.StatusInternalServerError) + return errors.Wrapf(err, "failed to permanent delete GroupMember with userId=%s", userId) } return nil } -func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) { +func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, error) { if err := groupSyncable.IsValid(); err != nil { return nil, err } @@ -475,46 +474,34 @@ func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) switch groupSyncable.Type { case model.GroupSyncableTypeTeam: if _, err := s.Team().Get(groupSyncable.SyncableId); err != nil { - var nfErr *store.ErrNotFound - switch { - case errors.As(err, &nfErr): - return nil, model.NewAppError("CreateGroupSyncable", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) - default: - return nil, model.NewAppError("CreateGroupSyncable", "app.team.get.finding.app_error", nil, err.Error(), http.StatusInternalServerError) - } + return nil, err } insertErr = s.GetMaster().Insert(groupSyncableToGroupTeam(groupSyncable)) case model.GroupSyncableTypeChannel: if _, err := s.Channel().Get(groupSyncable.SyncableId, false); err != nil { - var nfErr *store.ErrNotFound - switch { - case errors.As(err, &nfErr): - return nil, model.NewAppError("CreateGroupSyncable", "store.sql_channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound) - default: - return nil, model.NewAppError("CreateGroupSyncable", "store.sql_channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError) - } + return nil, err } insertErr = s.GetMaster().Insert(groupSyncableToGroupChannel(groupSyncable)) default: - return nil, model.NewAppError("SqlGroupStore.GroupCreateGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId, http.StatusInternalServerError) + return nil, fmt.Errorf("invalid GroupSyncableType: %s", groupSyncable.Type) } if insertErr != nil { - return nil, model.NewAppError("SqlGroupStore.GroupCreateGroupSyncable", "store.insert_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+insertErr.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(insertErr, "unable to insert GroupSyncable") } return groupSyncable, nil } -func (s *SqlGroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) { +func (s *SqlGroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) { groupSyncable, err := s.getGroupSyncable(groupID, syncableID, syncableType) if err != nil { if err == sql.ErrNoRows { - return nil, model.NewAppError("SqlGroupStore.GroupGetGroupSyncable", "store.sql_group.no_rows", nil, err.Error(), http.StatusNotFound) + return nil, store.NewErrNotFound("GroupSyncable", fmt.Sprintf("groupId=%s, syncableId=%s, syncableType=%s", groupID, syncableID, syncableType)) } - return nil, model.NewAppError("SqlGroupStore.GroupGetGroupSyncable", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find GroupSyncable with groupId=%s, syncableId=%s, syncableType=%s", groupID, syncableID, syncableType) } return groupSyncable, nil @@ -566,13 +553,9 @@ func (s *SqlGroupStore) getGroupSyncable(groupID string, syncableID string, sync return &groupSyncable, nil } -func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) { +func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, error) { args := map[string]interface{}{"GroupId": groupID} - appErrF := func(msg string) *model.AppError { - return model.NewAppError("SqlGroupStore.GroupGetAllGroupSyncablesByGroup", "store.select_error", nil, msg, http.StatusInternalServerError) - } - groupSyncables := []*model.GroupSyncable{} switch syncableType { @@ -591,7 +574,7 @@ func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableTy results := []*groupTeamJoin{} _, err := s.GetReplica().Select(&results, sqlQuery, args) if err != nil { - return nil, appErrF(err.Error()) + return nil, errors.Wrapf(err, "failed to find GroupTeams with groupId=%s", groupID) } for _, result := range results { groupSyncable := &model.GroupSyncable{ @@ -627,7 +610,7 @@ func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableTy results := []*groupChannelJoin{} _, err := s.GetReplica().Select(&results, sqlQuery, args) if err != nil { - return nil, appErrF(err.Error()) + return nil, errors.Wrapf(err, "failed to find GroupChannels with groupId=%s", groupID) } for _, result := range results { groupSyncable := &model.GroupSyncable{ @@ -652,13 +635,13 @@ func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableTy return groupSyncables, nil } -func (s *SqlGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) { +func (s *SqlGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, error) { retrievedGroupSyncable, err := s.getGroupSyncable(groupSyncable.GroupId, groupSyncable.SyncableId, groupSyncable.Type) if err != nil { if err == sql.ErrNoRows { - return nil, model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.sql_group.no_rows", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(store.NewErrNotFound("GroupSyncable", fmt.Sprintf("groupId=%s, syncableId=%s, syncableType=%s", groupSyncable.GroupId, groupSyncable.SyncableId, groupSyncable.Type)), "GroupSyncable not found") } - return nil, model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.select_error", nil, "GroupId="+groupSyncable.GroupId+", SyncableId="+groupSyncable.SyncableId+", SyncableType="+groupSyncable.Type.String()+", "+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find GroupSyncable with groupId=%s, syncableId=%s, syncableType=%s", groupSyncable.GroupId, groupSyncable.SyncableId, groupSyncable.Type) } if err := groupSyncable.IsValid(); err != nil { @@ -667,7 +650,7 @@ func (s *SqlGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) // If updating DeleteAt it can only be to 0 if groupSyncable.DeleteAt != retrievedGroupSyncable.DeleteAt && groupSyncable.DeleteAt != 0 { - return nil, model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "model.group.delete_at.app_error", nil, "", http.StatusInternalServerError) + return nil, errors.New("DeleteAt should be 0 when updating") } // Reset these properties, don't update them based on input @@ -680,27 +663,27 @@ func (s *SqlGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) case model.GroupSyncableTypeChannel: _, err = s.GetMaster().Update(groupSyncableToGroupChannel(groupSyncable)) default: - return nil, model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId, http.StatusInternalServerError) + return nil, fmt.Errorf("invalid GroupSyncableType: %s", groupSyncable.Type) } if err != nil { - return nil, model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to update GroupSyncable") } return groupSyncable, nil } -func (s *SqlGroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) { +func (s *SqlGroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) { groupSyncable, err := s.getGroupSyncable(groupID, syncableID, syncableType) if err != nil { if err == sql.ErrNoRows { - return nil, model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.sql_group.no_rows", nil, "Id="+groupID+", "+err.Error(), http.StatusNotFound) + return nil, store.NewErrNotFound("GroupSyncable", fmt.Sprintf("groupId=%s, syncableId=%s, syncableType=%s", groupID, syncableID, syncableType)) } - return nil, model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find GroupSyncable with groupId=%s, syncableId=%s, syncableType=%s", groupID, syncableID, syncableType) } if groupSyncable.DeleteAt != 0 { - return nil, model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.sql_group.group_syncable_already_deleted", nil, "group_id="+groupID+"syncable_id="+syncableID, http.StatusBadRequest) + return nil, store.NewErrInvalidInput("GroupSyncable", "", fmt.Sprintf("<%s, %s, %s>", groupSyncable.GroupId, groupSyncable.SyncableId, groupSyncable.Type)) } time := model.GetMillis() @@ -713,18 +696,18 @@ func (s *SqlGroupStore) DeleteGroupSyncable(groupID string, syncableID string, s case model.GroupSyncableTypeChannel: _, err = s.GetMaster().Update(groupSyncableToGroupChannel(groupSyncable)) default: - return nil, model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId, http.StatusInternalServerError) + return nil, fmt.Errorf("invalid GroupSyncableType: %s", groupSyncable.Type) } if err != nil { - return nil, model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to update GroupSyncable") } return groupSyncable, nil } -func (s *SqlGroupStore) TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, *model.AppError) { - query := s.getQueryBuilder().Select("GroupMembers.UserId", "GroupTeams.TeamId"). +func (s *SqlGroupStore) TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, error) { + builder := s.getQueryBuilder().Select("GroupMembers.UserId", "GroupTeams.TeamId"). From("GroupMembers"). Join("GroupTeams ON GroupTeams.GroupId = GroupMembers.GroupId"). Join("UserGroups ON UserGroups.Id = GroupMembers.GroupId"). @@ -741,26 +724,26 @@ func (s *SqlGroupStore) TeamMembersToAdd(since int64, teamID *string) ([]*model. Where("(GroupMembers.CreateAt >= ? OR GroupTeams.UpdateAt >= ?)", since, since) if teamID != nil { - query = query.Where(sq.Eq{"Teams.Id": *teamID}) + builder = builder.Where(sq.Eq{"Teams.Id": *teamID}) } - sql, params, err := query.ToSql() + query, params, err := builder.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.TeamMembersToAdd", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "team_members_to_add_tosql") } var teamMembers []*model.UserTeamIDPair - _, err = s.GetReplica().Select(&teamMembers, sql, params...) + _, err = s.GetReplica().Select(&teamMembers, query, params...) if err != nil { - return nil, model.NewAppError("SqlGroupStore.TeamMembersToAdd", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to find UserTeamIDPairs") } return teamMembers, nil } -func (s *SqlGroupStore) ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, *model.AppError) { - query := s.getQueryBuilder().Select("GroupMembers.UserId", "GroupChannels.ChannelId"). +func (s *SqlGroupStore) ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, error) { + builder := s.getQueryBuilder().Select("GroupMembers.UserId", "GroupChannels.ChannelId"). From("GroupMembers"). Join("GroupChannels ON GroupChannels.GroupId = GroupMembers.GroupId"). Join("UserGroups ON UserGroups.Id = GroupMembers.GroupId"). @@ -778,19 +761,19 @@ func (s *SqlGroupStore) ChannelMembersToAdd(since int64, channelID *string) ([]* Where("(GroupMembers.CreateAt >= ? OR GroupChannels.UpdateAt >= ?)", since, since) if channelID != nil { - query = query.Where(sq.Eq{"Channels.Id": *channelID}) + builder = builder.Where(sq.Eq{"Channels.Id": *channelID}) } - sql, params, err := query.ToSql() + query, params, err := builder.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.ChannelMembersToAdd", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "channel_members_to_add_tosql") } var channelMembers []*model.UserChannelIDPair - _, err = s.GetReplica().Select(&channelMembers, sql, params...) + _, err = s.GetReplica().Select(&channelMembers, query, params...) if err != nil { - return nil, model.NewAppError("SqlGroupStore.ChannelMembersToAdd", "store.select_error", nil, "", http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to find UserChannelIDPairs") } return channelMembers, nil @@ -810,7 +793,7 @@ func groupSyncableToGroupChannel(groupSyncable *model.GroupSyncable) *groupChann } } -func (s *SqlGroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError) { +func (s *SqlGroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, error) { whereStmt := ` (TeamMembers.TeamId, TeamMembers.UserId) @@ -833,7 +816,7 @@ func (s *SqlGroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember Teams.Id, GroupMembers.UserId)` - query := s.getQueryBuilder().Select( + builder := s.getQueryBuilder().Select( "TeamMembers.TeamId", "TeamMembers.UserId", "TeamMembers.Roles", @@ -849,41 +832,41 @@ func (s *SqlGroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember Where(whereStmt) if teamID != nil { - query = query.Where(sq.Eq{"TeamMembers.TeamId": *teamID}) + builder = builder.Where(sq.Eq{"TeamMembers.TeamId": *teamID}) } - sql, params, err := query.ToSql() + query, params, err := builder.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.TeamMembersToRemove", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "team_members_to_remove_tosql") } var teamMembers []*model.TeamMember - _, err = s.GetReplica().Select(&teamMembers, sql, params...) + _, err = s.GetReplica().Select(&teamMembers, query, params...) if err != nil { - return nil, model.NewAppError("SqlGroupStore.TeamMembersToRemove", "store.select_error", nil, "", http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to find TeamMembers") } return teamMembers, nil } -func (s *SqlGroupStore) CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, *model.AppError) { +func (s *SqlGroupStore) CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, error) { countQuery := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeChannel, selectCountGroups, channelId, opts) countQueryString, args, err := countQuery.ToSql() if err != nil { - return int64(0), model.NewAppError("SqlGroupStore.CountGroupsByChannel", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return int64(0), errors.Wrap(err, "count_groups_by_channel_tosql") } count, err := s.GetReplica().SelectInt(countQueryString, args...) if err != nil { - return int64(0), model.NewAppError("SqlGroupStore.CountGroupsByChannel", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return int64(0), errors.Wrapf(err, "failed to count Groups by channel with channelId=%s", channelId) } return count, nil } -func (s *SqlGroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) { +func (s *SqlGroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, error) { query := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeChannel, selectGroups, channelId, opts) if opts.PageOpts != nil { @@ -893,20 +876,20 @@ func (s *SqlGroupStore) GetGroupsByChannel(channelId string, opts model.GroupSea queryString, args, err := query.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.GetGroupsByChannel", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "get_groups_by_channel_tosql") } var groups []*model.GroupWithSchemeAdmin _, err = s.GetReplica().Select(&groups, queryString, args...) if err != nil { - return nil, model.NewAppError("SqlGroupStore.GetGroupsByChannel", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find Groups with channelId=%s", channelId) } return groups, nil } -func (s *SqlGroupStore) ChannelMembersToRemove(channelID *string) ([]*model.ChannelMember, *model.AppError) { +func (s *SqlGroupStore) ChannelMembersToRemove(channelID *string) ([]*model.ChannelMember, error) { whereStmt := ` (ChannelMembers.ChannelId, ChannelMembers.UserId) @@ -929,7 +912,7 @@ func (s *SqlGroupStore) ChannelMembersToRemove(channelID *string) ([]*model.Chan Channels.Id, GroupMembers.UserId)` - query := s.getQueryBuilder().Select( + builder := s.getQueryBuilder().Select( "ChannelMembers.ChannelId", "ChannelMembers.UserId", "ChannelMembers.LastViewedAt", @@ -949,19 +932,19 @@ func (s *SqlGroupStore) ChannelMembersToRemove(channelID *string) ([]*model.Chan Where(whereStmt) if channelID != nil { - query = query.Where(sq.Eq{"ChannelMembers.ChannelId": *channelID}) + builder = builder.Where(sq.Eq{"ChannelMembers.ChannelId": *channelID}) } - sql, params, err := query.ToSql() + query, params, err := builder.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.ChannelMembersToRemove", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "channel_members_to_remove_tosql") } var channelMembers []*model.ChannelMember - _, err = s.GetReplica().Select(&channelMembers, sql, params...) + _, err = s.GetReplica().Select(&channelMembers, query, params...) if err != nil { - return nil, model.NewAppError("SqlGroupStore.ChannelMembersToRemove", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to find ChannelMembers") } return channelMembers, nil @@ -1080,23 +1063,23 @@ func (s *SqlGroupStore) getGroupsAssociatedToChannelsByTeam(st model.GroupSyncab return query } -func (s *SqlGroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, *model.AppError) { +func (s *SqlGroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, error) { countQuery := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeTeam, selectCountGroups, teamId, opts) countQueryString, args, err := countQuery.ToSql() if err != nil { - return int64(0), model.NewAppError("SqlGroupStore.CountGroupsByTeam", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return int64(0), errors.Wrap(err, "count_groups_by_team_tosql") } count, err := s.GetReplica().SelectInt(countQueryString, args...) if err != nil { - return int64(0), model.NewAppError("SqlGroupStore.CountGroupsByTeam", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return int64(0), errors.Wrapf(err, "failed to count Groups with teamId=%s", teamId) } return count, nil } -func (s *SqlGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) { +func (s *SqlGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, error) { query := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeTeam, selectGroups, teamId, opts) if opts.PageOpts != nil { @@ -1106,20 +1089,20 @@ func (s *SqlGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpt queryString, args, err := query.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.GetGroupsByTeam", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "get_groups_by_team_tosql") } var groups []*model.GroupWithSchemeAdmin _, err = s.GetReplica().Select(&groups, queryString, args...) if err != nil { - return nil, model.NewAppError("SqlGroupStore.GetGroupsByTeam", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find Groups with teamId=%s", teamId) } return groups, nil } -func (s *SqlGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError) { +func (s *SqlGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, error) { query := s.getGroupsAssociatedToChannelsByTeam(model.GroupSyncableTypeTeam, teamId, opts) if opts.PageOpts != nil { @@ -1129,14 +1112,14 @@ func (s *SqlGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts queryString, args, err := query.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.GetGroupsAssociatedToChannelsByTeam", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "get_groups_associated_to_channel_by_team_tosql") } var tgroups []*model.GroupsAssociatedToChannelWithSchemeAdmin _, err = s.GetReplica().Select(&tgroups, queryString, args...) if err != nil { - return nil, model.NewAppError("SqlGroupStore.GetGroupsAssociatedToChannelsByTeam", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find Groups with teamId=%s", teamId) } groups := map[string][]*model.GroupWithSchemeAdmin{} @@ -1155,7 +1138,7 @@ func (s *SqlGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts return groups, nil } -func (s *SqlGroupStore) GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) { +func (s *SqlGroupStore) GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, error) { var groups []*model.Group groupsQuery := s.getQueryBuilder().Select("g.*") @@ -1263,11 +1246,11 @@ func (s *SqlGroupStore) GetGroups(page, perPage int, opts model.GroupSearchOpts) queryString, args, err := groupsQuery.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.GetGroups", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "get_groups_tosql") } if _, err = s.GetReplica().Select(&groups, queryString, args...); err != nil { - return nil, model.NewAppError("SqlGroupStore.GetGroups", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to find Groups") } return groups, nil @@ -1293,9 +1276,9 @@ func (s *SqlGroupStore) teamMembersMinusGroupMembersQuery(teamID string, groupID Where("GroupMembers.DeleteAt = 0"). Where(fmt.Sprintf("GroupMembers.GroupId IN ('%s')", strings.Join(groupIDs, "', '"))) - sql, _ := subQuery.MustSql() + query, _ := subQuery.MustSql() - query := s.getQueryBuilder().Select(selectStr). + builder := s.getQueryBuilder().Select(selectStr). From("TeamMembers"). Join("Teams ON Teams.Id = TeamMembers.TeamId"). Join("Users ON Users.Id = TeamMembers.UserId"). @@ -1307,29 +1290,29 @@ func (s *SqlGroupStore) teamMembersMinusGroupMembersQuery(teamID string, groupID Where("Users.DeleteAt = 0"). Where("Bots.UserId IS NULL"). Where("Teams.Id = ?", teamID). - Where(fmt.Sprintf("Users.Id NOT IN (%s)", sql)) + Where(fmt.Sprintf("Users.Id NOT IN (%s)", query)) if !isCount { - query = query.GroupBy("Users.Id, TeamMembers.SchemeGuest, TeamMembers.SchemeAdmin, TeamMembers.SchemeUser") + builder = builder.GroupBy("Users.Id, TeamMembers.SchemeGuest, TeamMembers.SchemeAdmin, TeamMembers.SchemeUser") } - return query + return builder } // TeamMembersMinusGroupMembers returns the set of users on the given team minus the set of users in the given // groups. -func (s *SqlGroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, *model.AppError) { +func (s *SqlGroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, error) { query := s.teamMembersMinusGroupMembersQuery(teamID, groupIDs, false) query = query.OrderBy("Users.Username ASC").Limit(uint64(perPage)).Offset(uint64(page * perPage)) queryString, args, err := query.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.TeamMembersMinusGroupMembers", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "team_members_minus_group_members") } var users []*model.UserWithGroups if _, err = s.GetReplica().Select(&users, queryString, args...); err != nil { - return nil, model.NewAppError("SqlGroupStore.TeamMembersMinusGroupMembers", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to find UserWithGroups") } return users, nil @@ -1337,15 +1320,15 @@ func (s *SqlGroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []s // CountTeamMembersMinusGroupMembers returns the count of the set of users on the given team minus the set of users // in the given groups. -func (s *SqlGroupStore) CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, *model.AppError) { +func (s *SqlGroupStore) CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, error) { queryString, args, err := s.teamMembersMinusGroupMembersQuery(teamID, groupIDs, true).ToSql() if err != nil { - return 0, model.NewAppError("SqlGroupStore.CountTeamMembersMinusGroupMembers", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, errors.Wrap(err, "count_team_members_minus_group_members_tosql") } var count int64 if count, err = s.GetReplica().SelectInt(queryString, args...); err != nil { - return 0, model.NewAppError("SqlGroupStore.CountTeamMembersMinusGroupMembers", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return 0, errors.Wrap(err, "failed to count TeamMembers minus GroupMembers") } return count, nil @@ -1371,9 +1354,9 @@ func (s *SqlGroupStore) channelMembersMinusGroupMembersQuery(channelID string, g Where("GroupMembers.DeleteAt = 0"). Where(fmt.Sprintf("GroupMembers.GroupId IN ('%s')", strings.Join(groupIDs, "', '"))) - sql, _ := subQuery.MustSql() + query, _ := subQuery.MustSql() - query := s.getQueryBuilder().Select(selectStr). + builder := s.getQueryBuilder().Select(selectStr). From("ChannelMembers"). Join("Channels ON Channels.Id = ChannelMembers.ChannelId"). Join("Users ON Users.Id = ChannelMembers.UserId"). @@ -1384,29 +1367,29 @@ func (s *SqlGroupStore) channelMembersMinusGroupMembersQuery(channelID string, g Where("Users.DeleteAt = 0"). Where("Bots.UserId IS NULL"). Where("Channels.Id = ?", channelID). - Where(fmt.Sprintf("Users.Id NOT IN (%s)", sql)) + Where(fmt.Sprintf("Users.Id NOT IN (%s)", query)) if !isCount { - query = query.GroupBy("Users.Id, ChannelMembers.SchemeGuest, ChannelMembers.SchemeAdmin, ChannelMembers.SchemeUser") + builder = builder.GroupBy("Users.Id, ChannelMembers.SchemeGuest, ChannelMembers.SchemeAdmin, ChannelMembers.SchemeUser") } - return query + return builder } // ChannelMembersMinusGroupMembers returns the set of users in the given channel minus the set of users in the given // groups. -func (s *SqlGroupStore) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, *model.AppError) { +func (s *SqlGroupStore) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, error) { query := s.channelMembersMinusGroupMembersQuery(channelID, groupIDs, false) query = query.OrderBy("Users.Username ASC").Limit(uint64(perPage)).Offset(uint64(page * perPage)) queryString, args, err := query.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.ChannelMembersMinusGroupMembers", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "channel_members_minus_group_members_tosql") } var users []*model.UserWithGroups if _, err = s.GetReplica().Select(&users, queryString, args...); err != nil { - return nil, model.NewAppError("SqlGroupStore.ChannelMembersMinusGroupMembers", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to find UserWithGroups") } return users, nil @@ -1414,24 +1397,24 @@ func (s *SqlGroupStore) ChannelMembersMinusGroupMembers(channelID string, groupI // CountChannelMembersMinusGroupMembers returns the count of the set of users in the given channel minus the set of users // in the given groups. -func (s *SqlGroupStore) CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, *model.AppError) { +func (s *SqlGroupStore) CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, error) { queryString, args, err := s.channelMembersMinusGroupMembersQuery(channelID, groupIDs, true).ToSql() if err != nil { - return 0, model.NewAppError("SqlGroupStore.CountChannelMembersMinusGroupMembers", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, errors.Wrap(err, "count_channel_members_minus_group_members_tosql") } var count int64 if count, err = s.GetReplica().SelectInt(queryString, args...); err != nil { - return 0, model.NewAppError("SqlGroupStore.CountChannelMembersMinusGroupMembers", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return 0, errors.Wrap(err, "failed to count ChannelMembers") } return count, nil } -func (s *SqlGroupStore) AdminRoleGroupsForSyncableMember(userID, syncableID string, syncableType model.GroupSyncableType) ([]string, *model.AppError) { +func (s *SqlGroupStore) AdminRoleGroupsForSyncableMember(userID, syncableID string, syncableType model.GroupSyncableType) ([]string, error) { var groupIds []string - sql := fmt.Sprintf(` + query := fmt.Sprintf(` SELECT GroupMembers.GroupId FROM @@ -1445,61 +1428,61 @@ func (s *SqlGroupStore) AdminRoleGroupsForSyncableMember(userID, syncableID stri AND Group%[1]ss.DeleteAt = 0 AND Group%[1]ss.SchemeAdmin = TRUE`, syncableType) - _, err := s.GetReplica().Select(&groupIds, sql, map[string]interface{}{"UserId": userID, fmt.Sprintf("%sId", syncableType): syncableID}) + _, err := s.GetReplica().Select(&groupIds, query, map[string]interface{}{"UserId": userID, fmt.Sprintf("%sId", syncableType): syncableID}) if err != nil { - return nil, model.NewAppError("SqlGroupStore AdminRoleGroupsForSyncableMember", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to find Group ids") } return groupIds, nil } -func (s *SqlGroupStore) PermittedSyncableAdmins(syncableID string, syncableType model.GroupSyncableType) ([]string, *model.AppError) { - query := s.getQueryBuilder().Select("UserId"). +func (s *SqlGroupStore) PermittedSyncableAdmins(syncableID string, syncableType model.GroupSyncableType) ([]string, error) { + builder := s.getQueryBuilder().Select("UserId"). From(fmt.Sprintf("Group%ss", syncableType)). Join(fmt.Sprintf("GroupMembers ON GroupMembers.GroupId = Group%ss.GroupId AND Group%[1]ss.SchemeAdmin = TRUE AND GroupMembers.DeleteAt = 0", syncableType.String())).Where(fmt.Sprintf("Group%[1]ss.%[1]sId = ?", syncableType.String()), syncableID) - sql, args, err := query.ToSql() + query, args, err := builder.ToSql() if err != nil { - return nil, model.NewAppError("SqlGroupStore.PermittedSyncableAdmins", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "permitted_syncable_admins_tosql") } var userIDs []string - if _, err = s.GetReplica().Select(&userIDs, sql, args...); err != nil { - return nil, model.NewAppError("SqlGroupStore.PermittedSyncableAdmins", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + if _, err = s.GetReplica().Select(&userIDs, query, args...); err != nil { + return nil, errors.Wrapf(err, "failed to find User ids") } return userIDs, nil } -func (s *SqlGroupStore) GroupCount() (int64, *model.AppError) { +func (s *SqlGroupStore) GroupCount() (int64, error) { return s.countTable("UserGroups") } -func (s *SqlGroupStore) GroupTeamCount() (int64, *model.AppError) { +func (s *SqlGroupStore) GroupTeamCount() (int64, error) { return s.countTable("GroupTeams") } -func (s *SqlGroupStore) GroupChannelCount() (int64, *model.AppError) { +func (s *SqlGroupStore) GroupChannelCount() (int64, error) { return s.countTable("GroupChannels") } -func (s *SqlGroupStore) GroupMemberCount() (int64, *model.AppError) { +func (s *SqlGroupStore) GroupMemberCount() (int64, error) { return s.countTable("GroupMembers") } -func (s *SqlGroupStore) DistinctGroupMemberCount() (int64, *model.AppError) { +func (s *SqlGroupStore) DistinctGroupMemberCount() (int64, error) { return s.countTableWithSelectAndWhere("COUNT(DISTINCT UserId)", "GroupMembers", nil) } -func (s *SqlGroupStore) GroupCountWithAllowReference() (int64, *model.AppError) { +func (s *SqlGroupStore) GroupCountWithAllowReference() (int64, error) { return s.countTableWithSelectAndWhere("COUNT(*)", "UserGroups", sq.Eq{"AllowReference": true, "DeleteAt": 0}) } -func (s *SqlGroupStore) countTable(tableName string) (int64, *model.AppError) { +func (s *SqlGroupStore) countTable(tableName string) (int64, error) { return s.countTableWithSelectAndWhere("COUNT(*)", tableName, nil) } -func (s *SqlGroupStore) countTableWithSelectAndWhere(selectStr, tableName string, whereStmt map[string]interface{}) (int64, *model.AppError) { +func (s *SqlGroupStore) countTableWithSelectAndWhere(selectStr, tableName string, whereStmt map[string]interface{}) (int64, error) { if whereStmt == nil { whereStmt = sq.Eq{"DeleteAt": 0} } @@ -1508,12 +1491,12 @@ func (s *SqlGroupStore) countTableWithSelectAndWhere(selectStr, tableName string sql, args, err := query.ToSql() if err != nil { - return 0, model.NewAppError("SqlGroupStore.countTableWithSelect", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, errors.Wrap(err, "count_table_with_select_and_where_tosql") } count, err := s.GetReplica().SelectInt(sql, args...) if err != nil { - return 0, model.NewAppError("SqlGroupStore.countTableWithSelect", "store.select_error", nil, err.Error(), http.StatusInternalServerError) + return 0, errors.Wrapf(err, "failed to count from table %s", tableName) } return count, nil diff --git a/store/store.go b/store/store.go index bc6b283b2b..a615093d7b 100644 --- a/store/store.go +++ b/store/store.go @@ -688,90 +688,90 @@ type UserTermsOfServiceStore interface { } type GroupStore interface { - Create(group *model.Group) (*model.Group, *model.AppError) - Get(groupID string) (*model.Group, *model.AppError) - GetByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError) - GetByIDs(groupIDs []string) ([]*model.Group, *model.AppError) - GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError) - GetAllBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) - GetByUser(userId string) ([]*model.Group, *model.AppError) - Update(group *model.Group) (*model.Group, *model.AppError) - Delete(groupID string) (*model.Group, *model.AppError) + Create(group *model.Group) (*model.Group, error) + Get(groupID string) (*model.Group, error) + GetByName(name string, opts model.GroupSearchOpts) (*model.Group, error) + GetByIDs(groupIDs []string) ([]*model.Group, error) + GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, error) + GetAllBySource(groupSource model.GroupSource) ([]*model.Group, error) + GetByUser(userId string) ([]*model.Group, error) + Update(group *model.Group) (*model.Group, error) + Delete(groupID string) (*model.Group, error) - GetMemberUsers(groupID string) ([]*model.User, *model.AppError) - GetMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, *model.AppError) - GetMemberCount(groupID string) (int64, *model.AppError) + GetMemberUsers(groupID string) ([]*model.User, error) + GetMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, error) + GetMemberCount(groupID string) (int64, error) - GetMemberUsersInTeam(groupID string, teamID string) ([]*model.User, *model.AppError) - GetMemberUsersNotInChannel(groupID string, channelID string) ([]*model.User, *model.AppError) + GetMemberUsersInTeam(groupID string, teamID string) ([]*model.User, error) + GetMemberUsersNotInChannel(groupID string, channelID string) ([]*model.User, error) - UpsertMember(groupID string, userID string) (*model.GroupMember, *model.AppError) - DeleteMember(groupID string, userID string) (*model.GroupMember, *model.AppError) - PermanentDeleteMembersByUser(userId string) *model.AppError + UpsertMember(groupID string, userID string) (*model.GroupMember, error) + DeleteMember(groupID string, userID string) (*model.GroupMember, error) + PermanentDeleteMembersByUser(userId string) error - CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) - GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) - GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) - UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) - DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) + CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, error) + GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) + GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, error) + UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, error) + DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) // TeamMembersToAdd returns a slice of UserTeamIDPair that need newly created memberships // based on the groups configurations. The returned list can be optionally scoped to a single given team. // // Typically since will be the last successful group sync time. - TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, *model.AppError) + TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, error) // ChannelMembersToAdd returns a slice of UserChannelIDPair that need newly created memberships // based on the groups configurations. The returned list can be optionally scoped to a single given channel. // // Typically since will be the last successful group sync time. - ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, *model.AppError) + ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, error) // TeamMembersToRemove returns all team members that should be removed based on group constraints. - TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError) + TeamMembersToRemove(teamID *string) ([]*model.TeamMember, error) // ChannelMembersToRemove returns all channel members that should be removed based on group constraints. - ChannelMembersToRemove(channelID *string) ([]*model.ChannelMember, *model.AppError) + ChannelMembersToRemove(channelID *string) ([]*model.ChannelMember, error) - GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) - CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, *model.AppError) + GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, error) + CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, error) - GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) - GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError) - CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, *model.AppError) + GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, error) + GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, error) + CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, error) - GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) + GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, error) - TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, *model.AppError) - CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, *model.AppError) - ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, *model.AppError) - CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, *model.AppError) + TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, error) + CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, error) + ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, error) + CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, error) // AdminRoleGroupsForSyncableMember returns the IDs of all of the groups that the user is a member of that are // configured as SchemeAdmin: true for the given syncable. - AdminRoleGroupsForSyncableMember(userID, syncableID string, syncableType model.GroupSyncableType) ([]string, *model.AppError) + AdminRoleGroupsForSyncableMember(userID, syncableID string, syncableType model.GroupSyncableType) ([]string, error) // PermittedSyncableAdmins returns the IDs of all of the user who are permitted by the group syncable to have // the admin role for the given syncable. - PermittedSyncableAdmins(syncableID string, syncableType model.GroupSyncableType) ([]string, *model.AppError) + PermittedSyncableAdmins(syncableID string, syncableType model.GroupSyncableType) ([]string, error) // GroupCount returns the total count of records in the UserGroups table. - GroupCount() (int64, *model.AppError) + GroupCount() (int64, error) // GroupTeamCount returns the total count of records in the GroupTeams table. - GroupTeamCount() (int64, *model.AppError) + GroupTeamCount() (int64, error) // GroupChannelCount returns the total count of records in the GroupChannels table. - GroupChannelCount() (int64, *model.AppError) + GroupChannelCount() (int64, error) // GroupMemberCount returns the total count of records in the GroupMembers table. - GroupMemberCount() (int64, *model.AppError) + GroupMemberCount() (int64, error) // DistinctGroupMemberCount returns the count of records in the GroupMembers table with distinct UserId values. - DistinctGroupMemberCount() (int64, *model.AppError) + DistinctGroupMemberCount() (int64, error) // GroupCountWithAllowReference returns the count of records in the Groups table with AllowReference set to true. - GroupCountWithAllowReference() (int64, *model.AppError) + GroupCountWithAllowReference() (int64, error) } type LinkMetadataStore interface { diff --git a/store/storetest/group_store.go b/store/storetest/group_store.go index 912722acd6..9e984fac76 100644 --- a/store/storetest/group_store.go +++ b/store/storetest/group_store.go @@ -4,6 +4,7 @@ package storetest import ( + "errors" "fmt" "math" "sort" @@ -116,7 +117,9 @@ func testGroupStoreCreate(t *testing.T, ss store.Store) { data, err := ss.Group().Create(g2) require.Nil(t, data) require.NotNil(t, err) - require.Equal(t, err.Id, "model.group.display_name.app_error") + var appErr *model.AppError + require.True(t, errors.As(err, &appErr)) + require.Equal(t, appErr.Id, "model.group.display_name.app_error") // Won't accept a duplicate name g4 := &model.Group{ @@ -135,7 +138,8 @@ func testGroupStoreCreate(t *testing.T, ss store.Store) { } data, err = ss.Group().Create(g4b) require.Nil(t, data) - require.Equal(t, err.Id, "store.sql_group.unique_constraint") + require.Error(t, err) + require.Contains(t, err.Error(), fmt.Sprintf("Group with name %s already exists", *g4b.Name)) // Fields cannot be greater than max values g5 := &model.Group{ @@ -211,7 +215,8 @@ func testGroupStoreGet(t *testing.T, ss store.Store) { // Get an invalid group _, err = ss.Group().Get(model.NewId()) require.NotNil(t, err) - require.Equal(t, err.Id, "store.sql_group.no_rows") + var nfErr *store.ErrNotFound + require.True(t, errors.As(err, &nfErr)) } func testGroupStoreGetByName(t *testing.T, ss store.Store) { @@ -246,7 +251,8 @@ func testGroupStoreGetByName(t *testing.T, ss store.Store) { // Get an invalid group _, err = ss.Group().GetByName(model.NewId(), g1Opts) require.NotNil(t, err) - require.Equal(t, err.Id, "store.sql_group.no_rows") + var nfErr *store.ErrNotFound + require.True(t, errors.As(err, &nfErr)) } func testGroupStoreGetByIDs(t *testing.T, ss store.Store) { @@ -310,7 +316,8 @@ func testGroupStoreGetByRemoteID(t *testing.T, ss store.Store) { // Get an invalid group _, err = ss.Group().GetByRemoteID(model.NewId(), model.GroupSource("fake")) require.NotNil(t, err) - require.Equal(t, err.Id, "store.sql_group.no_rows") + var nfErr *store.ErrNotFound + require.True(t, errors.As(err, &nfErr)) } func testGroupStoreGetAllByType(t *testing.T, ss store.Store) { @@ -464,7 +471,9 @@ func testGroupStoreUpdate(t *testing.T, ss store.Store) { }) require.Nil(t, data) require.NotNil(t, err) - require.Equal(t, err.Id, "model.group.display_name.app_error") + var appErr *model.AppError + require.True(t, errors.As(err, &appErr)) + require.Equal(t, appErr.Id, "model.group.display_name.app_error") // Create another Group g2 := &model.Group{ @@ -486,7 +495,8 @@ func testGroupStoreUpdate(t *testing.T, ss store.Store) { Description: model.NewId(), RemoteId: model.NewId(), }) - require.Equal(t, err.Id, "store.sql_group.unique_constraint") + require.Error(t, err) + require.Contains(t, err.Error(), fmt.Sprintf("Group with name %s already exists", *g1Update.Name)) // Cannot update CreateAt someVal := model.GetMillis() @@ -498,7 +508,8 @@ func testGroupStoreUpdate(t *testing.T, ss store.Store) { // Cannot update DeleteAt to non-zero d1.DeleteAt = 1 _, err = ss.Group().Update(d1) - require.Equal(t, "model.group.delete_at.app_error", err.Id) + require.Error(t, err) + require.Contains(t, err.Error(), "DeleteAt should be 0 when updating") //...except for 0 for DeleteAt d1.DeleteAt = 0 @@ -548,11 +559,12 @@ func testGroupStoreDelete(t *testing.T, ss store.Store) { // Try and delete a nonexistent group _, err = ss.Group().Delete(model.NewId()) require.NotNil(t, err) - require.Equal(t, err.Id, "store.sql_group.no_rows") + var nfErr *store.ErrNotFound + require.True(t, errors.As(err, &nfErr)) // Cannot delete again _, err = ss.Group().Delete(d1.Id) - require.Equal(t, err.Id, "store.sql_group.no_rows") + require.True(t, errors.As(err, &nfErr)) } func testGroupGetMemberUsers(t *testing.T, ss store.Store) { @@ -942,7 +954,8 @@ func testUpsertMember(t *testing.T, ss store.Store) { // Invalid GroupId _, err = ss.Group().UpsertMember(model.NewId(), user.Id) - require.Equal(t, err.Id, "store.insert_error") + require.Error(t, err) + require.Contains(t, err.Error(), "failed to get UserGroup with") // Restores a deleted member // Ensure new CreateAt > previous CreateAt for the same (groupId, userId) @@ -998,15 +1011,16 @@ func testGroupDeleteMember(t *testing.T, ss store.Store) { // Delete an already deleted member _, err = ss.Group().DeleteMember(group.Id, user.Id) - require.Equal(t, err.Id, "store.sql_group.no_rows") + var nfErr *store.ErrNotFound + require.True(t, errors.As(err, &nfErr)) // Delete with non-existent User _, err = ss.Group().DeleteMember(group.Id, model.NewId()) - require.Equal(t, err.Id, "store.sql_group.no_rows") + require.True(t, errors.As(err, &nfErr)) // Delete non-existent Group _, err = ss.Group().DeleteMember(model.NewId(), group.Id) - require.Equal(t, err.Id, "store.sql_group.no_rows") + require.True(t, errors.As(err, &nfErr)) } func testGroupPermanentDeleteMembersByUser(t *testing.T, ss store.Store) { @@ -1048,7 +1062,9 @@ func testGroupPermanentDeleteMembersByUser(t *testing.T, ss store.Store) { func testCreateGroupSyncable(t *testing.T, ss store.Store) { // Invalid GroupID _, err := ss.Group().CreateGroupSyncable(model.NewGroupTeam("x", model.NewId(), false)) - require.Equal(t, err.Id, "model.group_syncable.group_id.app_error") + var appErr *model.AppError + require.True(t, errors.As(err, &appErr)) + require.Equal(t, appErr.Id, "model.group_syncable.group_id.app_error") // Create Group g1 := &model.Group{ @@ -1225,12 +1241,13 @@ func testUpdateGroupSyncable(t *testing.T, ss store.Store) { // Non-existent Group gt2 := model.NewGroupTeam(model.NewId(), team.Id, false) _, err = ss.Group().UpdateGroupSyncable(gt2) - require.Equal(t, err.Id, "store.sql_group.no_rows") + var nfErr *store.ErrNotFound + require.True(t, errors.As(err, &nfErr)) // Non-existent Team gt3 := model.NewGroupTeam(group.Id, model.NewId(), false) _, err = ss.Group().UpdateGroupSyncable(gt3) - require.Equal(t, err.Id, "store.sql_group.no_rows") + require.True(t, errors.As(err, &nfErr)) // Cannot update CreateAt or DeleteAt origCreateAt := d1.CreateAt @@ -1243,7 +1260,8 @@ func testUpdateGroupSyncable(t *testing.T, ss store.Store) { // Cannot update DeleteAt to arbitrary value d1.DeleteAt = 1 _, err = ss.Group().UpdateGroupSyncable(d1) - require.Equal(t, "model.group.delete_at.app_error", err.Id) + require.Error(t, err) + require.Contains(t, err.Error(), "DeleteAt should be 0 when updating") // Can update DeleteAt to 0 d1.DeleteAt = 0 @@ -1284,11 +1302,12 @@ func testDeleteGroupSyncable(t *testing.T, ss store.Store) { // Non-existent Group _, err = ss.Group().DeleteGroupSyncable(model.NewId(), groupTeam.SyncableId, model.GroupSyncableTypeTeam) - require.Equal(t, err.Id, "store.sql_group.no_rows") + var nfErr *store.ErrNotFound + require.True(t, errors.As(err, &nfErr)) // Non-existent Team _, err = ss.Group().DeleteGroupSyncable(groupTeam.GroupId, model.NewId(), model.GroupSyncableTypeTeam) - require.Equal(t, err.Id, "store.sql_group.no_rows") + require.True(t, errors.As(err, &nfErr)) // Happy path... d1, err := ss.Group().DeleteGroupSyncable(groupTeam.GroupId, groupTeam.SyncableId, model.GroupSyncableTypeTeam) @@ -1303,7 +1322,8 @@ func testDeleteGroupSyncable(t *testing.T, ss store.Store) { // Record already deleted _, err = ss.Group().DeleteGroupSyncable(d1.GroupId, d1.SyncableId, d1.Type) require.NotNil(t, err) - require.Equal(t, err.Id, "store.sql_group.group_syncable_already_deleted") + var invErr *store.ErrInvalidInput + require.True(t, errors.As(err, &invErr)) } func testTeamMembersToAdd(t *testing.T, ss store.Store) { diff --git a/store/storetest/mocks/GroupStore.go b/store/storetest/mocks/GroupStore.go index d3461d1f17..db3790c7de 100644 --- a/store/storetest/mocks/GroupStore.go +++ b/store/storetest/mocks/GroupStore.go @@ -15,7 +15,7 @@ type GroupStore struct { } // AdminRoleGroupsForSyncableMember provides a mock function with given fields: userID, syncableID, syncableType -func (_m *GroupStore) AdminRoleGroupsForSyncableMember(userID string, syncableID string, syncableType model.GroupSyncableType) ([]string, *model.AppError) { +func (_m *GroupStore) AdminRoleGroupsForSyncableMember(userID string, syncableID string, syncableType model.GroupSyncableType) ([]string, error) { ret := _m.Called(userID, syncableID, syncableType) var r0 []string @@ -27,20 +27,18 @@ func (_m *GroupStore) AdminRoleGroupsForSyncableMember(userID string, syncableID } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, string, model.GroupSyncableType) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, string, model.GroupSyncableType) error); ok { r1 = rf(userID, syncableID, syncableType) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // ChannelMembersMinusGroupMembers provides a mock function with given fields: channelID, groupIDs, page, perPage -func (_m *GroupStore) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, *model.AppError) { +func (_m *GroupStore) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, error) { ret := _m.Called(channelID, groupIDs, page, perPage) var r0 []*model.UserWithGroups @@ -52,20 +50,18 @@ func (_m *GroupStore) ChannelMembersMinusGroupMembers(channelID string, groupIDs } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, []string, int, int) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, []string, int, int) error); ok { r1 = rf(channelID, groupIDs, page, perPage) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // ChannelMembersToAdd provides a mock function with given fields: since, channelID -func (_m *GroupStore) ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, *model.AppError) { +func (_m *GroupStore) ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, error) { ret := _m.Called(since, channelID) var r0 []*model.UserChannelIDPair @@ -77,20 +73,18 @@ func (_m *GroupStore) ChannelMembersToAdd(since int64, channelID *string) ([]*mo } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(int64, *string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(int64, *string) error); ok { r1 = rf(since, channelID) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // ChannelMembersToRemove provides a mock function with given fields: channelID -func (_m *GroupStore) ChannelMembersToRemove(channelID *string) ([]*model.ChannelMember, *model.AppError) { +func (_m *GroupStore) ChannelMembersToRemove(channelID *string) ([]*model.ChannelMember, error) { ret := _m.Called(channelID) var r0 []*model.ChannelMember @@ -102,20 +96,18 @@ func (_m *GroupStore) ChannelMembersToRemove(channelID *string) ([]*model.Channe } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(*string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(*string) error); ok { r1 = rf(channelID) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // CountChannelMembersMinusGroupMembers provides a mock function with given fields: channelID, groupIDs -func (_m *GroupStore) CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, *model.AppError) { +func (_m *GroupStore) CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, error) { ret := _m.Called(channelID, groupIDs) var r0 int64 @@ -125,20 +117,18 @@ func (_m *GroupStore) CountChannelMembersMinusGroupMembers(channelID string, gro r0 = ret.Get(0).(int64) } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, []string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, []string) error); ok { r1 = rf(channelID, groupIDs) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // CountGroupsByChannel provides a mock function with given fields: channelId, opts -func (_m *GroupStore) CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, *model.AppError) { +func (_m *GroupStore) CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, error) { ret := _m.Called(channelId, opts) var r0 int64 @@ -148,20 +138,18 @@ func (_m *GroupStore) CountGroupsByChannel(channelId string, opts model.GroupSea r0 = ret.Get(0).(int64) } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) error); ok { r1 = rf(channelId, opts) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // CountGroupsByTeam provides a mock function with given fields: teamId, opts -func (_m *GroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, *model.AppError) { +func (_m *GroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, error) { ret := _m.Called(teamId, opts) var r0 int64 @@ -171,20 +159,18 @@ func (_m *GroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpt r0 = ret.Get(0).(int64) } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) error); ok { r1 = rf(teamId, opts) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // CountTeamMembersMinusGroupMembers provides a mock function with given fields: teamID, groupIDs -func (_m *GroupStore) CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, *model.AppError) { +func (_m *GroupStore) CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, error) { ret := _m.Called(teamID, groupIDs) var r0 int64 @@ -194,20 +180,18 @@ func (_m *GroupStore) CountTeamMembersMinusGroupMembers(teamID string, groupIDs r0 = ret.Get(0).(int64) } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, []string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, []string) error); ok { r1 = rf(teamID, groupIDs) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // Create provides a mock function with given fields: group -func (_m *GroupStore) Create(group *model.Group) (*model.Group, *model.AppError) { +func (_m *GroupStore) Create(group *model.Group) (*model.Group, error) { ret := _m.Called(group) var r0 *model.Group @@ -219,20 +203,18 @@ func (_m *GroupStore) Create(group *model.Group) (*model.Group, *model.AppError) } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(*model.Group) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(*model.Group) error); ok { r1 = rf(group) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // CreateGroupSyncable provides a mock function with given fields: groupSyncable -func (_m *GroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) { +func (_m *GroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, error) { ret := _m.Called(groupSyncable) var r0 *model.GroupSyncable @@ -244,20 +226,18 @@ func (_m *GroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (* } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(*model.GroupSyncable) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(*model.GroupSyncable) error); ok { r1 = rf(groupSyncable) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // Delete provides a mock function with given fields: groupID -func (_m *GroupStore) Delete(groupID string) (*model.Group, *model.AppError) { +func (_m *GroupStore) Delete(groupID string) (*model.Group, error) { ret := _m.Called(groupID) var r0 *model.Group @@ -269,20 +249,18 @@ func (_m *GroupStore) Delete(groupID string) (*model.Group, *model.AppError) { } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(groupID) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // DeleteGroupSyncable provides a mock function with given fields: groupID, syncableID, syncableType -func (_m *GroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) { +func (_m *GroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) { ret := _m.Called(groupID, syncableID, syncableType) var r0 *model.GroupSyncable @@ -294,20 +272,18 @@ func (_m *GroupStore) DeleteGroupSyncable(groupID string, syncableID string, syn } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, string, model.GroupSyncableType) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, string, model.GroupSyncableType) error); ok { r1 = rf(groupID, syncableID, syncableType) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // DeleteMember provides a mock function with given fields: groupID, userID -func (_m *GroupStore) DeleteMember(groupID string, userID string) (*model.GroupMember, *model.AppError) { +func (_m *GroupStore) DeleteMember(groupID string, userID string) (*model.GroupMember, error) { ret := _m.Called(groupID, userID) var r0 *model.GroupMember @@ -319,20 +295,18 @@ func (_m *GroupStore) DeleteMember(groupID string, userID string) (*model.GroupM } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, string) error); ok { r1 = rf(groupID, userID) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // DistinctGroupMemberCount provides a mock function with given fields: -func (_m *GroupStore) DistinctGroupMemberCount() (int64, *model.AppError) { +func (_m *GroupStore) DistinctGroupMemberCount() (int64, error) { ret := _m.Called() var r0 int64 @@ -342,20 +316,18 @@ func (_m *GroupStore) DistinctGroupMemberCount() (int64, *model.AppError) { r0 = ret.Get(0).(int64) } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func() *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // Get provides a mock function with given fields: groupID -func (_m *GroupStore) Get(groupID string) (*model.Group, *model.AppError) { +func (_m *GroupStore) Get(groupID string) (*model.Group, error) { ret := _m.Called(groupID) var r0 *model.Group @@ -367,20 +339,18 @@ func (_m *GroupStore) Get(groupID string) (*model.Group, *model.AppError) { } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(groupID) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetAllBySource provides a mock function with given fields: groupSource -func (_m *GroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) { +func (_m *GroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.Group, error) { ret := _m.Called(groupSource) var r0 []*model.Group @@ -392,20 +362,18 @@ func (_m *GroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.Gr } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(model.GroupSource) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(model.GroupSource) error); ok { r1 = rf(groupSource) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetAllGroupSyncablesByGroupId provides a mock function with given fields: groupID, syncableType -func (_m *GroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) { +func (_m *GroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, error) { ret := _m.Called(groupID, syncableType) var r0 []*model.GroupSyncable @@ -417,20 +385,18 @@ func (_m *GroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, model.GroupSyncableType) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, model.GroupSyncableType) error); ok { r1 = rf(groupID, syncableType) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetByIDs provides a mock function with given fields: groupIDs -func (_m *GroupStore) GetByIDs(groupIDs []string) ([]*model.Group, *model.AppError) { +func (_m *GroupStore) GetByIDs(groupIDs []string) ([]*model.Group, error) { ret := _m.Called(groupIDs) var r0 []*model.Group @@ -442,20 +408,18 @@ func (_m *GroupStore) GetByIDs(groupIDs []string) ([]*model.Group, *model.AppErr } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func([]string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func([]string) error); ok { r1 = rf(groupIDs) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetByName provides a mock function with given fields: name, opts -func (_m *GroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError) { +func (_m *GroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, error) { ret := _m.Called(name, opts) var r0 *model.Group @@ -467,20 +431,18 @@ func (_m *GroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) error); ok { r1 = rf(name, opts) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetByRemoteID provides a mock function with given fields: remoteID, groupSource -func (_m *GroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError) { +func (_m *GroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, error) { ret := _m.Called(remoteID, groupSource) var r0 *model.Group @@ -492,20 +454,18 @@ func (_m *GroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSour } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, model.GroupSource) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, model.GroupSource) error); ok { r1 = rf(remoteID, groupSource) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetByUser provides a mock function with given fields: userId -func (_m *GroupStore) GetByUser(userId string) ([]*model.Group, *model.AppError) { +func (_m *GroupStore) GetByUser(userId string) ([]*model.Group, error) { ret := _m.Called(userId) var r0 []*model.Group @@ -517,20 +477,18 @@ func (_m *GroupStore) GetByUser(userId string) ([]*model.Group, *model.AppError) } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(userId) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetGroupSyncable provides a mock function with given fields: groupID, syncableID, syncableType -func (_m *GroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) { +func (_m *GroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) { ret := _m.Called(groupID, syncableID, syncableType) var r0 *model.GroupSyncable @@ -542,20 +500,18 @@ func (_m *GroupStore) GetGroupSyncable(groupID string, syncableID string, syncab } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, string, model.GroupSyncableType) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, string, model.GroupSyncableType) error); ok { r1 = rf(groupID, syncableID, syncableType) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetGroups provides a mock function with given fields: page, perPage, opts -func (_m *GroupStore) GetGroups(page int, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) { +func (_m *GroupStore) GetGroups(page int, perPage int, opts model.GroupSearchOpts) ([]*model.Group, error) { ret := _m.Called(page, perPage, opts) var r0 []*model.Group @@ -567,20 +523,18 @@ func (_m *GroupStore) GetGroups(page int, perPage int, opts model.GroupSearchOpt } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(int, int, model.GroupSearchOpts) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(int, int, model.GroupSearchOpts) error); ok { r1 = rf(page, perPage, opts) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetGroupsAssociatedToChannelsByTeam provides a mock function with given fields: teamId, opts -func (_m *GroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError) { +func (_m *GroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, error) { ret := _m.Called(teamId, opts) var r0 map[string][]*model.GroupWithSchemeAdmin @@ -592,20 +546,18 @@ func (_m *GroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts mo } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) error); ok { r1 = rf(teamId, opts) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetGroupsByChannel provides a mock function with given fields: channelId, opts -func (_m *GroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) { +func (_m *GroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, error) { ret := _m.Called(channelId, opts) var r0 []*model.GroupWithSchemeAdmin @@ -617,20 +569,18 @@ func (_m *GroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearc } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) error); ok { r1 = rf(channelId, opts) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetGroupsByTeam provides a mock function with given fields: teamId, opts -func (_m *GroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) { +func (_m *GroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, error) { ret := _m.Called(teamId, opts) var r0 []*model.GroupWithSchemeAdmin @@ -642,20 +592,18 @@ func (_m *GroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) error); ok { r1 = rf(teamId, opts) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetMemberCount provides a mock function with given fields: groupID -func (_m *GroupStore) GetMemberCount(groupID string) (int64, *model.AppError) { +func (_m *GroupStore) GetMemberCount(groupID string) (int64, error) { ret := _m.Called(groupID) var r0 int64 @@ -665,20 +613,18 @@ func (_m *GroupStore) GetMemberCount(groupID string) (int64, *model.AppError) { r0 = ret.Get(0).(int64) } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(groupID) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetMemberUsers provides a mock function with given fields: groupID -func (_m *GroupStore) GetMemberUsers(groupID string) ([]*model.User, *model.AppError) { +func (_m *GroupStore) GetMemberUsers(groupID string) ([]*model.User, error) { ret := _m.Called(groupID) var r0 []*model.User @@ -690,20 +636,18 @@ func (_m *GroupStore) GetMemberUsers(groupID string) ([]*model.User, *model.AppE } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(groupID) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetMemberUsersInTeam provides a mock function with given fields: groupID, teamID -func (_m *GroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]*model.User, *model.AppError) { +func (_m *GroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]*model.User, error) { ret := _m.Called(groupID, teamID) var r0 []*model.User @@ -715,20 +659,18 @@ func (_m *GroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]*mo } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, string) error); ok { r1 = rf(groupID, teamID) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetMemberUsersNotInChannel provides a mock function with given fields: groupID, channelID -func (_m *GroupStore) GetMemberUsersNotInChannel(groupID string, channelID string) ([]*model.User, *model.AppError) { +func (_m *GroupStore) GetMemberUsersNotInChannel(groupID string, channelID string) ([]*model.User, error) { ret := _m.Called(groupID, channelID) var r0 []*model.User @@ -740,20 +682,18 @@ func (_m *GroupStore) GetMemberUsersNotInChannel(groupID string, channelID strin } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, string) error); ok { r1 = rf(groupID, channelID) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetMemberUsersPage provides a mock function with given fields: groupID, page, perPage -func (_m *GroupStore) GetMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, *model.AppError) { +func (_m *GroupStore) GetMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, error) { ret := _m.Called(groupID, page, perPage) var r0 []*model.User @@ -765,20 +705,18 @@ func (_m *GroupStore) GetMemberUsersPage(groupID string, page int, perPage int) } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, int, int) error); ok { r1 = rf(groupID, page, perPage) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GroupChannelCount provides a mock function with given fields: -func (_m *GroupStore) GroupChannelCount() (int64, *model.AppError) { +func (_m *GroupStore) GroupChannelCount() (int64, error) { ret := _m.Called() var r0 int64 @@ -788,20 +726,18 @@ func (_m *GroupStore) GroupChannelCount() (int64, *model.AppError) { r0 = ret.Get(0).(int64) } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func() *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GroupCount provides a mock function with given fields: -func (_m *GroupStore) GroupCount() (int64, *model.AppError) { +func (_m *GroupStore) GroupCount() (int64, error) { ret := _m.Called() var r0 int64 @@ -811,20 +747,18 @@ func (_m *GroupStore) GroupCount() (int64, *model.AppError) { r0 = ret.Get(0).(int64) } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func() *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GroupCountWithAllowReference provides a mock function with given fields: -func (_m *GroupStore) GroupCountWithAllowReference() (int64, *model.AppError) { +func (_m *GroupStore) GroupCountWithAllowReference() (int64, error) { ret := _m.Called() var r0 int64 @@ -834,20 +768,18 @@ func (_m *GroupStore) GroupCountWithAllowReference() (int64, *model.AppError) { r0 = ret.Get(0).(int64) } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func() *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GroupMemberCount provides a mock function with given fields: -func (_m *GroupStore) GroupMemberCount() (int64, *model.AppError) { +func (_m *GroupStore) GroupMemberCount() (int64, error) { ret := _m.Called() var r0 int64 @@ -857,20 +789,18 @@ func (_m *GroupStore) GroupMemberCount() (int64, *model.AppError) { r0 = ret.Get(0).(int64) } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func() *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GroupTeamCount provides a mock function with given fields: -func (_m *GroupStore) GroupTeamCount() (int64, *model.AppError) { +func (_m *GroupStore) GroupTeamCount() (int64, error) { ret := _m.Called() var r0 int64 @@ -880,36 +810,32 @@ func (_m *GroupStore) GroupTeamCount() (int64, *model.AppError) { r0 = ret.Get(0).(int64) } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func() *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // PermanentDeleteMembersByUser provides a mock function with given fields: userId -func (_m *GroupStore) PermanentDeleteMembersByUser(userId string) *model.AppError { +func (_m *GroupStore) PermanentDeleteMembersByUser(userId string) error { ret := _m.Called(userId) - var r0 *model.AppError - if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(userId) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } + r0 = ret.Error(0) } return r0 } // PermittedSyncableAdmins provides a mock function with given fields: syncableID, syncableType -func (_m *GroupStore) PermittedSyncableAdmins(syncableID string, syncableType model.GroupSyncableType) ([]string, *model.AppError) { +func (_m *GroupStore) PermittedSyncableAdmins(syncableID string, syncableType model.GroupSyncableType) ([]string, error) { ret := _m.Called(syncableID, syncableType) var r0 []string @@ -921,20 +847,18 @@ func (_m *GroupStore) PermittedSyncableAdmins(syncableID string, syncableType mo } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, model.GroupSyncableType) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, model.GroupSyncableType) error); ok { r1 = rf(syncableID, syncableType) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // TeamMembersMinusGroupMembers provides a mock function with given fields: teamID, groupIDs, page, perPage -func (_m *GroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, *model.AppError) { +func (_m *GroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, error) { ret := _m.Called(teamID, groupIDs, page, perPage) var r0 []*model.UserWithGroups @@ -946,20 +870,18 @@ func (_m *GroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []str } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, []string, int, int) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, []string, int, int) error); ok { r1 = rf(teamID, groupIDs, page, perPage) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // TeamMembersToAdd provides a mock function with given fields: since, teamID -func (_m *GroupStore) TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, *model.AppError) { +func (_m *GroupStore) TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, error) { ret := _m.Called(since, teamID) var r0 []*model.UserTeamIDPair @@ -971,20 +893,18 @@ func (_m *GroupStore) TeamMembersToAdd(since int64, teamID *string) ([]*model.Us } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(int64, *string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(int64, *string) error); ok { r1 = rf(since, teamID) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // TeamMembersToRemove provides a mock function with given fields: teamID -func (_m *GroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError) { +func (_m *GroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, error) { ret := _m.Called(teamID) var r0 []*model.TeamMember @@ -996,20 +916,18 @@ func (_m *GroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(*string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(*string) error); ok { r1 = rf(teamID) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // Update provides a mock function with given fields: group -func (_m *GroupStore) Update(group *model.Group) (*model.Group, *model.AppError) { +func (_m *GroupStore) Update(group *model.Group) (*model.Group, error) { ret := _m.Called(group) var r0 *model.Group @@ -1021,20 +939,18 @@ func (_m *GroupStore) Update(group *model.Group) (*model.Group, *model.AppError) } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(*model.Group) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(*model.Group) error); ok { r1 = rf(group) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // UpdateGroupSyncable provides a mock function with given fields: groupSyncable -func (_m *GroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) { +func (_m *GroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, error) { ret := _m.Called(groupSyncable) var r0 *model.GroupSyncable @@ -1046,20 +962,18 @@ func (_m *GroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (* } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(*model.GroupSyncable) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(*model.GroupSyncable) error); ok { r1 = rf(groupSyncable) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // UpsertMember provides a mock function with given fields: groupID, userID -func (_m *GroupStore) UpsertMember(groupID string, userID string) (*model.GroupMember, *model.AppError) { +func (_m *GroupStore) UpsertMember(groupID string, userID string) (*model.GroupMember, error) { ret := _m.Called(groupID, userID) var r0 *model.GroupMember @@ -1071,13 +985,11 @@ func (_m *GroupStore) UpsertMember(groupID string, userID string) (*model.GroupM } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, string) error); ok { r1 = rf(groupID, userID) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 diff --git a/store/timerlayer/timerlayer.go b/store/timerlayer/timerlayer.go index d416a4004b..8ffb2514da 100644 --- a/store/timerlayer/timerlayer.go +++ b/store/timerlayer/timerlayer.go @@ -2909,7 +2909,7 @@ func (s *TimerLayerFileInfoStore) Upsert(info *model.FileInfo) (*model.FileInfo, return result, err } -func (s *TimerLayerGroupStore) AdminRoleGroupsForSyncableMember(userID string, syncableID string, syncableType model.GroupSyncableType) ([]string, *model.AppError) { +func (s *TimerLayerGroupStore) AdminRoleGroupsForSyncableMember(userID string, syncableID string, syncableType model.GroupSyncableType) ([]string, error) { start := timemodule.Now() result, err := s.GroupStore.AdminRoleGroupsForSyncableMember(userID, syncableID, syncableType) @@ -2925,7 +2925,7 @@ func (s *TimerLayerGroupStore) AdminRoleGroupsForSyncableMember(userID string, s return result, err } -func (s *TimerLayerGroupStore) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, *model.AppError) { +func (s *TimerLayerGroupStore) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, error) { start := timemodule.Now() result, err := s.GroupStore.ChannelMembersMinusGroupMembers(channelID, groupIDs, page, perPage) @@ -2941,7 +2941,7 @@ func (s *TimerLayerGroupStore) ChannelMembersMinusGroupMembers(channelID string, return result, err } -func (s *TimerLayerGroupStore) ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, *model.AppError) { +func (s *TimerLayerGroupStore) ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, error) { start := timemodule.Now() result, err := s.GroupStore.ChannelMembersToAdd(since, channelID) @@ -2957,7 +2957,7 @@ func (s *TimerLayerGroupStore) ChannelMembersToAdd(since int64, channelID *strin return result, err } -func (s *TimerLayerGroupStore) ChannelMembersToRemove(channelID *string) ([]*model.ChannelMember, *model.AppError) { +func (s *TimerLayerGroupStore) ChannelMembersToRemove(channelID *string) ([]*model.ChannelMember, error) { start := timemodule.Now() result, err := s.GroupStore.ChannelMembersToRemove(channelID) @@ -2973,7 +2973,7 @@ func (s *TimerLayerGroupStore) ChannelMembersToRemove(channelID *string) ([]*mod return result, err } -func (s *TimerLayerGroupStore) CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, *model.AppError) { +func (s *TimerLayerGroupStore) CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, error) { start := timemodule.Now() result, err := s.GroupStore.CountChannelMembersMinusGroupMembers(channelID, groupIDs) @@ -2989,7 +2989,7 @@ func (s *TimerLayerGroupStore) CountChannelMembersMinusGroupMembers(channelID st return result, err } -func (s *TimerLayerGroupStore) CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, *model.AppError) { +func (s *TimerLayerGroupStore) CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, error) { start := timemodule.Now() result, err := s.GroupStore.CountGroupsByChannel(channelId, opts) @@ -3005,7 +3005,7 @@ func (s *TimerLayerGroupStore) CountGroupsByChannel(channelId string, opts model return result, err } -func (s *TimerLayerGroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, *model.AppError) { +func (s *TimerLayerGroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, error) { start := timemodule.Now() result, err := s.GroupStore.CountGroupsByTeam(teamId, opts) @@ -3021,7 +3021,7 @@ func (s *TimerLayerGroupStore) CountGroupsByTeam(teamId string, opts model.Group return result, err } -func (s *TimerLayerGroupStore) CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, *model.AppError) { +func (s *TimerLayerGroupStore) CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, error) { start := timemodule.Now() result, err := s.GroupStore.CountTeamMembersMinusGroupMembers(teamID, groupIDs) @@ -3037,7 +3037,7 @@ func (s *TimerLayerGroupStore) CountTeamMembersMinusGroupMembers(teamID string, return result, err } -func (s *TimerLayerGroupStore) Create(group *model.Group) (*model.Group, *model.AppError) { +func (s *TimerLayerGroupStore) Create(group *model.Group) (*model.Group, error) { start := timemodule.Now() result, err := s.GroupStore.Create(group) @@ -3053,7 +3053,7 @@ func (s *TimerLayerGroupStore) Create(group *model.Group) (*model.Group, *model. return result, err } -func (s *TimerLayerGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) { +func (s *TimerLayerGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, error) { start := timemodule.Now() result, err := s.GroupStore.CreateGroupSyncable(groupSyncable) @@ -3069,7 +3069,7 @@ func (s *TimerLayerGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyn return result, err } -func (s *TimerLayerGroupStore) Delete(groupID string) (*model.Group, *model.AppError) { +func (s *TimerLayerGroupStore) Delete(groupID string) (*model.Group, error) { start := timemodule.Now() result, err := s.GroupStore.Delete(groupID) @@ -3085,7 +3085,7 @@ func (s *TimerLayerGroupStore) Delete(groupID string) (*model.Group, *model.AppE return result, err } -func (s *TimerLayerGroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) { +func (s *TimerLayerGroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) { start := timemodule.Now() result, err := s.GroupStore.DeleteGroupSyncable(groupID, syncableID, syncableType) @@ -3101,7 +3101,7 @@ func (s *TimerLayerGroupStore) DeleteGroupSyncable(groupID string, syncableID st return result, err } -func (s *TimerLayerGroupStore) DeleteMember(groupID string, userID string) (*model.GroupMember, *model.AppError) { +func (s *TimerLayerGroupStore) DeleteMember(groupID string, userID string) (*model.GroupMember, error) { start := timemodule.Now() result, err := s.GroupStore.DeleteMember(groupID, userID) @@ -3117,7 +3117,7 @@ func (s *TimerLayerGroupStore) DeleteMember(groupID string, userID string) (*mod return result, err } -func (s *TimerLayerGroupStore) DistinctGroupMemberCount() (int64, *model.AppError) { +func (s *TimerLayerGroupStore) DistinctGroupMemberCount() (int64, error) { start := timemodule.Now() result, err := s.GroupStore.DistinctGroupMemberCount() @@ -3133,7 +3133,7 @@ func (s *TimerLayerGroupStore) DistinctGroupMemberCount() (int64, *model.AppErro return result, err } -func (s *TimerLayerGroupStore) Get(groupID string) (*model.Group, *model.AppError) { +func (s *TimerLayerGroupStore) Get(groupID string) (*model.Group, error) { start := timemodule.Now() result, err := s.GroupStore.Get(groupID) @@ -3149,7 +3149,7 @@ func (s *TimerLayerGroupStore) Get(groupID string) (*model.Group, *model.AppErro return result, err } -func (s *TimerLayerGroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) { +func (s *TimerLayerGroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.Group, error) { start := timemodule.Now() result, err := s.GroupStore.GetAllBySource(groupSource) @@ -3165,7 +3165,7 @@ func (s *TimerLayerGroupStore) GetAllBySource(groupSource model.GroupSource) ([] return result, err } -func (s *TimerLayerGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) { +func (s *TimerLayerGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, error) { start := timemodule.Now() result, err := s.GroupStore.GetAllGroupSyncablesByGroupId(groupID, syncableType) @@ -3181,7 +3181,7 @@ func (s *TimerLayerGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syn return result, err } -func (s *TimerLayerGroupStore) GetByIDs(groupIDs []string) ([]*model.Group, *model.AppError) { +func (s *TimerLayerGroupStore) GetByIDs(groupIDs []string) ([]*model.Group, error) { start := timemodule.Now() result, err := s.GroupStore.GetByIDs(groupIDs) @@ -3197,7 +3197,7 @@ func (s *TimerLayerGroupStore) GetByIDs(groupIDs []string) ([]*model.Group, *mod return result, err } -func (s *TimerLayerGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError) { +func (s *TimerLayerGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, error) { start := timemodule.Now() result, err := s.GroupStore.GetByName(name, opts) @@ -3213,7 +3213,7 @@ func (s *TimerLayerGroupStore) GetByName(name string, opts model.GroupSearchOpts return result, err } -func (s *TimerLayerGroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError) { +func (s *TimerLayerGroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, error) { start := timemodule.Now() result, err := s.GroupStore.GetByRemoteID(remoteID, groupSource) @@ -3229,7 +3229,7 @@ func (s *TimerLayerGroupStore) GetByRemoteID(remoteID string, groupSource model. return result, err } -func (s *TimerLayerGroupStore) GetByUser(userId string) ([]*model.Group, *model.AppError) { +func (s *TimerLayerGroupStore) GetByUser(userId string) ([]*model.Group, error) { start := timemodule.Now() result, err := s.GroupStore.GetByUser(userId) @@ -3245,7 +3245,7 @@ func (s *TimerLayerGroupStore) GetByUser(userId string) ([]*model.Group, *model. return result, err } -func (s *TimerLayerGroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) { +func (s *TimerLayerGroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) { start := timemodule.Now() result, err := s.GroupStore.GetGroupSyncable(groupID, syncableID, syncableType) @@ -3261,7 +3261,7 @@ func (s *TimerLayerGroupStore) GetGroupSyncable(groupID string, syncableID strin return result, err } -func (s *TimerLayerGroupStore) GetGroups(page int, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) { +func (s *TimerLayerGroupStore) GetGroups(page int, perPage int, opts model.GroupSearchOpts) ([]*model.Group, error) { start := timemodule.Now() result, err := s.GroupStore.GetGroups(page, perPage, opts) @@ -3277,7 +3277,7 @@ func (s *TimerLayerGroupStore) GetGroups(page int, perPage int, opts model.Group return result, err } -func (s *TimerLayerGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError) { +func (s *TimerLayerGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, error) { start := timemodule.Now() result, err := s.GroupStore.GetGroupsAssociatedToChannelsByTeam(teamId, opts) @@ -3293,7 +3293,7 @@ func (s *TimerLayerGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string return result, err } -func (s *TimerLayerGroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) { +func (s *TimerLayerGroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, error) { start := timemodule.Now() result, err := s.GroupStore.GetGroupsByChannel(channelId, opts) @@ -3309,7 +3309,7 @@ func (s *TimerLayerGroupStore) GetGroupsByChannel(channelId string, opts model.G return result, err } -func (s *TimerLayerGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) { +func (s *TimerLayerGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, error) { start := timemodule.Now() result, err := s.GroupStore.GetGroupsByTeam(teamId, opts) @@ -3325,7 +3325,7 @@ func (s *TimerLayerGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSe return result, err } -func (s *TimerLayerGroupStore) GetMemberCount(groupID string) (int64, *model.AppError) { +func (s *TimerLayerGroupStore) GetMemberCount(groupID string) (int64, error) { start := timemodule.Now() result, err := s.GroupStore.GetMemberCount(groupID) @@ -3341,7 +3341,7 @@ func (s *TimerLayerGroupStore) GetMemberCount(groupID string) (int64, *model.App return result, err } -func (s *TimerLayerGroupStore) GetMemberUsers(groupID string) ([]*model.User, *model.AppError) { +func (s *TimerLayerGroupStore) GetMemberUsers(groupID string) ([]*model.User, error) { start := timemodule.Now() result, err := s.GroupStore.GetMemberUsers(groupID) @@ -3357,7 +3357,7 @@ func (s *TimerLayerGroupStore) GetMemberUsers(groupID string) ([]*model.User, *m return result, err } -func (s *TimerLayerGroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]*model.User, *model.AppError) { +func (s *TimerLayerGroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]*model.User, error) { start := timemodule.Now() result, err := s.GroupStore.GetMemberUsersInTeam(groupID, teamID) @@ -3373,7 +3373,7 @@ func (s *TimerLayerGroupStore) GetMemberUsersInTeam(groupID string, teamID strin return result, err } -func (s *TimerLayerGroupStore) GetMemberUsersNotInChannel(groupID string, channelID string) ([]*model.User, *model.AppError) { +func (s *TimerLayerGroupStore) GetMemberUsersNotInChannel(groupID string, channelID string) ([]*model.User, error) { start := timemodule.Now() result, err := s.GroupStore.GetMemberUsersNotInChannel(groupID, channelID) @@ -3389,7 +3389,7 @@ func (s *TimerLayerGroupStore) GetMemberUsersNotInChannel(groupID string, channe return result, err } -func (s *TimerLayerGroupStore) GetMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, *model.AppError) { +func (s *TimerLayerGroupStore) GetMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, error) { start := timemodule.Now() result, err := s.GroupStore.GetMemberUsersPage(groupID, page, perPage) @@ -3405,7 +3405,7 @@ func (s *TimerLayerGroupStore) GetMemberUsersPage(groupID string, page int, perP return result, err } -func (s *TimerLayerGroupStore) GroupChannelCount() (int64, *model.AppError) { +func (s *TimerLayerGroupStore) GroupChannelCount() (int64, error) { start := timemodule.Now() result, err := s.GroupStore.GroupChannelCount() @@ -3421,7 +3421,7 @@ func (s *TimerLayerGroupStore) GroupChannelCount() (int64, *model.AppError) { return result, err } -func (s *TimerLayerGroupStore) GroupCount() (int64, *model.AppError) { +func (s *TimerLayerGroupStore) GroupCount() (int64, error) { start := timemodule.Now() result, err := s.GroupStore.GroupCount() @@ -3437,7 +3437,7 @@ func (s *TimerLayerGroupStore) GroupCount() (int64, *model.AppError) { return result, err } -func (s *TimerLayerGroupStore) GroupCountWithAllowReference() (int64, *model.AppError) { +func (s *TimerLayerGroupStore) GroupCountWithAllowReference() (int64, error) { start := timemodule.Now() result, err := s.GroupStore.GroupCountWithAllowReference() @@ -3453,7 +3453,7 @@ func (s *TimerLayerGroupStore) GroupCountWithAllowReference() (int64, *model.App return result, err } -func (s *TimerLayerGroupStore) GroupMemberCount() (int64, *model.AppError) { +func (s *TimerLayerGroupStore) GroupMemberCount() (int64, error) { start := timemodule.Now() result, err := s.GroupStore.GroupMemberCount() @@ -3469,7 +3469,7 @@ func (s *TimerLayerGroupStore) GroupMemberCount() (int64, *model.AppError) { return result, err } -func (s *TimerLayerGroupStore) GroupTeamCount() (int64, *model.AppError) { +func (s *TimerLayerGroupStore) GroupTeamCount() (int64, error) { start := timemodule.Now() result, err := s.GroupStore.GroupTeamCount() @@ -3485,7 +3485,7 @@ func (s *TimerLayerGroupStore) GroupTeamCount() (int64, *model.AppError) { return result, err } -func (s *TimerLayerGroupStore) PermanentDeleteMembersByUser(userId string) *model.AppError { +func (s *TimerLayerGroupStore) PermanentDeleteMembersByUser(userId string) error { start := timemodule.Now() err := s.GroupStore.PermanentDeleteMembersByUser(userId) @@ -3501,7 +3501,7 @@ func (s *TimerLayerGroupStore) PermanentDeleteMembersByUser(userId string) *mode return err } -func (s *TimerLayerGroupStore) PermittedSyncableAdmins(syncableID string, syncableType model.GroupSyncableType) ([]string, *model.AppError) { +func (s *TimerLayerGroupStore) PermittedSyncableAdmins(syncableID string, syncableType model.GroupSyncableType) ([]string, error) { start := timemodule.Now() result, err := s.GroupStore.PermittedSyncableAdmins(syncableID, syncableType) @@ -3517,7 +3517,7 @@ func (s *TimerLayerGroupStore) PermittedSyncableAdmins(syncableID string, syncab return result, err } -func (s *TimerLayerGroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, *model.AppError) { +func (s *TimerLayerGroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, error) { start := timemodule.Now() result, err := s.GroupStore.TeamMembersMinusGroupMembers(teamID, groupIDs, page, perPage) @@ -3533,7 +3533,7 @@ func (s *TimerLayerGroupStore) TeamMembersMinusGroupMembers(teamID string, group return result, err } -func (s *TimerLayerGroupStore) TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, *model.AppError) { +func (s *TimerLayerGroupStore) TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, error) { start := timemodule.Now() result, err := s.GroupStore.TeamMembersToAdd(since, teamID) @@ -3549,7 +3549,7 @@ func (s *TimerLayerGroupStore) TeamMembersToAdd(since int64, teamID *string) ([] return result, err } -func (s *TimerLayerGroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError) { +func (s *TimerLayerGroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, error) { start := timemodule.Now() result, err := s.GroupStore.TeamMembersToRemove(teamID) @@ -3565,7 +3565,7 @@ func (s *TimerLayerGroupStore) TeamMembersToRemove(teamID *string) ([]*model.Tea return result, err } -func (s *TimerLayerGroupStore) Update(group *model.Group) (*model.Group, *model.AppError) { +func (s *TimerLayerGroupStore) Update(group *model.Group) (*model.Group, error) { start := timemodule.Now() result, err := s.GroupStore.Update(group) @@ -3581,7 +3581,7 @@ func (s *TimerLayerGroupStore) Update(group *model.Group) (*model.Group, *model. return result, err } -func (s *TimerLayerGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) { +func (s *TimerLayerGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, error) { start := timemodule.Now() result, err := s.GroupStore.UpdateGroupSyncable(groupSyncable) @@ -3597,7 +3597,7 @@ func (s *TimerLayerGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyn return result, err } -func (s *TimerLayerGroupStore) UpsertMember(groupID string, userID string) (*model.GroupMember, *model.AppError) { +func (s *TimerLayerGroupStore) UpsertMember(groupID string, userID string) (*model.GroupMember, error) { start := timemodule.Now() result, err := s.GroupStore.UpsertMember(groupID, userID)