diff --git a/app/channel.go b/app/channel.go index 804faaa1da..8cc5133508 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1632,15 +1632,36 @@ func (a *App) GetChannelsUserNotIn(teamId string, userId string, offset int, lim } func (a *App) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) { - return a.Srv().Store.Channel().GetPublicChannelsByIdsForTeam(teamId, channelIds) + list, err := a.Srv().Store.Channel().GetPublicChannelsByIdsForTeam(teamId, channelIds) + if err != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("GetPublicChannelsByIdsForTeam", "app.channel.get_channels_by_ids.not_found.app_error", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("GetPublicChannelsByIdsForTeam", "app.channel.get_channels_by_ids.get.app_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return list, nil } func (a *App) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) { - return a.Srv().Store.Channel().GetPublicChannelsForTeam(teamId, offset, limit) + list, err := a.Srv().Store.Channel().GetPublicChannelsForTeam(teamId, offset, limit) + if err != nil { + return nil, model.NewAppError("GetPublicChannelsForTeam", "app.channel.get_public_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + } + + return list, nil } func (a *App) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) { - return a.Srv().Store.Channel().GetPrivateChannelsForTeam(teamId, offset, limit) + list, err := a.Srv().Store.Channel().GetPrivateChannelsForTeam(teamId, offset, limit) + if err != nil { + return nil, model.NewAppError("GetPrivateChannelsForTeam", "app.channel.get_private_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + } + + return list, nil } func (a *App) GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) { @@ -1705,7 +1726,12 @@ func (a *App) GetChannelPinnedPostCount(channelId string) (int64, *model.AppErro } func (a *App) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) { - return a.Srv().Store.Channel().GetChannelCounts(teamId, userId) + counts, err := a.Srv().Store.Channel().GetChannelCounts(teamId, userId) + if err != nil { + return nil, model.NewAppError("SqlChannelStore.GetChannelCounts", "app.channel.get_channel_counts.get.app_error", nil, err.Error(), http.StatusInternalServerError) + } + + return counts, nil } func (a *App) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) { @@ -2094,7 +2120,13 @@ func (a *App) GetNumberOfChannelsOnTeam(teamId string) (int, *model.AppError) { // Get total number of channels on current team list, err := a.Srv().Store.Channel().GetTeamChannels(teamId) if err != nil { - return 0, err + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return 0, model.NewAppError("GetNumberOfChannelsOnTeam", "app.channel.get_channels.not_found.app_error", nil, nfErr.Error(), http.StatusNotFound) + default: + return 0, model.NewAppError("GetNumberOfChannelsOnTeam", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + } } return len(*list), nil } @@ -2415,8 +2447,8 @@ func (a *App) MoveChannel(team *model.Team, channel *model.Channel, user *model. } } - if appErr := a.Srv().Store.Channel().UpdateSidebarChannelCategoryOnMove(channel, team.Id); appErr != nil { - return appErr + if nErr := a.Srv().Store.Channel().UpdateSidebarChannelCategoryOnMove(channel, team.Id); nErr != nil { + return model.NewAppError("MoveChannel", "app.channel.sidebar_categories.app_error", nil, nErr.Error(), http.StatusInternalServerError) } channel.TeamId = team.Id diff --git a/app/integration_action.go b/app/integration_action.go index 1c2d403c79..ddc02a2430 100644 --- a/app/integration_action.go +++ b/app/integration_action.go @@ -78,7 +78,7 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st cchan := make(chan store.StoreResult, 1) go func() { channel, err := a.Srv().Store.Channel().GetForPost(postId) - cchan <- store.StoreResult{Data: channel, Err: err} + cchan <- store.StoreResult{Data: channel, NErr: err} close(cchan) }() @@ -133,8 +133,8 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st } else { post := result.Data.(*model.Post) result = <-cchan - if result.Err != nil { - return "", result.Err + if result.NErr != nil { + return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get_for_post.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) } channel := result.Data.(*model.Channel) diff --git a/app/team.go b/app/team.go index 95377450e1..b5c1c3020f 100644 --- a/app/team.go +++ b/app/team.go @@ -582,7 +582,7 @@ func (a *App) AddUserToTeamByToken(userId string, tokenId string) (*model.Team, if token.Type == TOKEN_TYPE_GUEST_INVITATION { channels, err := a.Srv().Store.Channel().GetChannelsByIds(strings.Split(tokenData["channels"], " "), false) if err != nil { - return nil, err + return nil, model.NewAppError("AddUserToTeamByToken", "app.channel.get_channels_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError) } for _, channel := range channels { @@ -1158,7 +1158,7 @@ func (a *App) RemoveTeamMemberFromTeam(teamMember *model.TeamMember, requestorId } if err := a.Srv().Store.Channel().ClearSidebarOnTeamLeave(user.Id, teamMember.TeamId); err != nil { - return err + return model.NewAppError("RemoveTeamMemberFromTeam", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError) } // delete the preferences that set the last channel used in the team and other team specific preferences @@ -1396,7 +1396,7 @@ func (a *App) prepareInviteGuestsToChannels(teamId string, guestsInvite *model.G cchan := make(chan store.StoreResult, 1) go func() { channels, err := a.Srv().Store.Channel().GetChannelsByIds(guestsInvite.Channels, false) - cchan <- store.StoreResult{Data: channels, Err: err} + cchan <- store.StoreResult{Data: channels, NErr: err} close(cchan) }() uchan := make(chan store.StoreResult, 1) @@ -1407,8 +1407,8 @@ func (a *App) prepareInviteGuestsToChannels(teamId string, guestsInvite *model.G }() result := <-cchan - if result.Err != nil { - return nil, nil, nil, result.Err + if result.NErr != nil { + return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", "app.channel.get_channels_by_ids.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) } channels := result.Data.([]*model.Channel) @@ -1432,7 +1432,7 @@ func (a *App) prepareInviteGuestsToChannels(teamId string, guestsInvite *model.G for _, channel := range channels { if channel.TeamId != teamId { - return nil, nil, nil, model.NewAppError("InviteGuestsToChannels", "api.team.invite_guests.channel_in_invalid_team.app_error", nil, "", http.StatusBadRequest) + return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", "api.team.invite_guests.channel_in_invalid_team.app_error", nil, "", http.StatusBadRequest) } } return user, team, channels, nil @@ -1440,7 +1440,7 @@ func (a *App) prepareInviteGuestsToChannels(teamId string, guestsInvite *model.G func (a *App) InviteGuestsToChannelsGracefully(teamId string, guestsInvite *model.GuestsInvite, senderId string) ([]*model.EmailInviteWithError, *model.AppError) { if !*a.Config().ServiceSettings.EnableEmailInvitations { - return nil, model.NewAppError("InviteNewUsersToTeam", "api.team.invite_members.disabled.app_error", nil, "", http.StatusNotImplemented) + return nil, model.NewAppError("InviteGuestsToChannelsGracefully", "api.team.invite_members.disabled.app_error", nil, "", http.StatusNotImplemented) } user, team, channels, err := a.prepareInviteGuestsToChannels(teamId, guestsInvite, senderId) @@ -1456,7 +1456,7 @@ func (a *App) InviteGuestsToChannelsGracefully(teamId string, guestsInvite *mode Error: nil, } if !CheckEmailDomain(email, *a.Config().GuestAccountsSettings.RestrictCreationToDomains) { - invite.Error = model.NewAppError("InviteNewUsersToTeam", "api.team.invite_members.invalid_email.app_error", map[string]interface{}{"Addresses": email}, "", http.StatusBadRequest) + invite.Error = model.NewAppError("InviteGuestsToChannelsGracefully", "api.team.invite_members.invalid_email.app_error", map[string]interface{}{"Addresses": email}, "", http.StatusBadRequest) } else { goodEmails = append(goodEmails, email) } @@ -1621,8 +1621,9 @@ func (a *App) PermanentDeleteTeam(team *model.Team) *model.AppError { } if channels, err := a.Srv().Store.Channel().GetTeamChannels(team.Id); err != nil { - if err.Id != "app.channel.get_channels.not_found.app_error" { - return err + var nfErr *store.ErrNotFound + if !errors.As(err, &nfErr) { + return model.NewAppError("PermanentDeleteTeam", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) } } else { for _, c := range *channels { diff --git a/app/user.go b/app/user.go index b9ac7bf846..aca4a49653 100644 --- a/app/user.go +++ b/app/user.go @@ -75,9 +75,9 @@ func (a *App) CreateUserWithToken(user *model.User, token *model.Token) (*model. } } - channels, err := a.Srv().Store.Channel().GetChannelsByIds(strings.Split(tokenData["channels"], " "), false) - if err != nil { - return nil, err + channels, nErr := a.Srv().Store.Channel().GetChannelsByIds(strings.Split(tokenData["channels"], " "), false) + if nErr != nil { + return nil, model.NewAppError("CreateUserWithToken", "app.channel.get_channels_by_ids.app_error", nil, nErr.Error(), http.StatusInternalServerError) } user.Email = tokenData["email"] diff --git a/i18n/en.json b/i18n/en.json index fb69d51532..5dd7172166 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -3298,6 +3298,10 @@ "id": "app.channel.get_by_name.missing.app_error", "translation": "Channel does not exist." }, + { + "id": "app.channel.get_channel_counts.get.app_error", + "translation": "Unable to get the channel counts." + }, { "id": "app.channel.get_channels.get.app_error", "translation": "Unable to get the channels." @@ -3306,6 +3310,18 @@ "id": "app.channel.get_channels.not_found.app_error", "translation": "No channels were found." }, + { + "id": "app.channel.get_channels_by_ids.app_error", + "translation": "Unable to get channels by ids." + }, + { + "id": "app.channel.get_channels_by_ids.get.app_error", + "translation": "Unable to get the channels." + }, + { + "id": "app.channel.get_channels_by_ids.not_found.app_error", + "translation": "No channel found." + }, { "id": "app.channel.get_deleted.existing.app_error", "translation": "Unable to find the existing deleted channel." @@ -3314,10 +3330,22 @@ "id": "app.channel.get_deleted.missing.app_error", "translation": "No deleted channels exist." }, + { + "id": "app.channel.get_for_post.app_error", + "translation": "Unable to get the channel for the given post." + }, { "id": "app.channel.get_more_channels.get.app_error", "translation": "Unable to get the channels." }, + { + "id": "app.channel.get_private_channels.get.app_error", + "translation": "Unable to get private channels." + }, + { + "id": "app.channel.get_public_channels.get.app_error", + "translation": "Unable to get public channels." + }, { "id": "app.channel.move_channel.members_do_not_match.error", "translation": "Unable to move a channel unless all its members are already members of the destination team." @@ -3350,6 +3378,10 @@ "id": "app.channel.restore.app_error", "translation": "Unable to restore the channel." }, + { + "id": "app.channel.sidebar_categories.app_error", + "translation": "Failed to insert record to database." + }, { "id": "app.channel.update.bad_id", "translation": "Unable to update the channel." @@ -7206,30 +7238,10 @@ "id": "store.sql_channel.get_by_scheme.app_error", "translation": "Unable to get the channels for the provided scheme." }, - { - "id": "store.sql_channel.get_channel_counts.get.app_error", - "translation": "Unable to get the channel counts." - }, { "id": "store.sql_channel.get_channels_batch_for_indexing.get.app_error", "translation": "Unable to get the channels batch for indexing." }, - { - "id": "store.sql_channel.get_channels_by_ids.app_error", - "translation": "Unable to get channels by ids." - }, - { - "id": "store.sql_channel.get_channels_by_ids.get.app_error", - "translation": "Unable to get the channels." - }, - { - "id": "store.sql_channel.get_channels_by_ids.not_found.app_error", - "translation": "No channel found." - }, - { - "id": "store.sql_channel.get_for_post.app_error", - "translation": "Unable to get the channel for the given post." - }, { "id": "store.sql_channel.get_member.app_error", "translation": "Unable to get the channel member." @@ -7258,14 +7270,6 @@ "id": "store.sql_channel.get_pinnedpost_count.app_error", "translation": "Unable to get the channel pinned post count." }, - { - "id": "store.sql_channel.get_private_channels.get.app_error", - "translation": "Unable to get private channels." - }, - { - "id": "store.sql_channel.get_public_channels.get.app_error", - "translation": "Unable to get public channels." - }, { "id": "store.sql_channel.get_unread.app_error", "translation": "Unable to get the channel unread messages." diff --git a/store/opentracinglayer/opentracinglayer.go b/store/opentracinglayer/opentracinglayer.go index f638727c6d..be53006f4f 100644 --- a/store/opentracinglayer/opentracinglayer.go +++ b/store/opentracinglayer/opentracinglayer.go @@ -577,7 +577,7 @@ func (s *OpenTracingLayerChannelStore) ClearCaches() { } -func (s *OpenTracingLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) *model.AppError { +func (s *OpenTracingLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) error { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.ClearSidebarOnTeamLeave") s.Root.Store.SetContext(newCtx) @@ -739,7 +739,7 @@ func (s *OpenTracingLayerChannelStore) Get(id string, allowFromCache bool) (*mod return result, err } -func (s *OpenTracingLayerChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetAll(teamId string) ([]*model.Channel, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetAll") s.Root.Store.SetContext(newCtx) @@ -919,7 +919,7 @@ func (s *OpenTracingLayerChannelStore) GetByNames(team_id string, names []string return result, err } -func (s *OpenTracingLayerChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetChannelCounts") s.Root.Store.SetContext(newCtx) @@ -1027,7 +1027,7 @@ func (s *OpenTracingLayerChannelStore) GetChannelsBatchForIndexing(startTime int return result, err } -func (s *OpenTracingLayerChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetChannelsByIds") s.Root.Store.SetContext(newCtx) @@ -1099,7 +1099,7 @@ func (s *OpenTracingLayerChannelStore) GetDeletedByName(team_id string, name str return result, err } -func (s *OpenTracingLayerChannelStore) GetForPost(postId string) (*model.Channel, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetForPost(postId string) (*model.Channel, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetForPost") s.Root.Store.SetContext(newCtx) @@ -1364,7 +1364,7 @@ func (s *OpenTracingLayerChannelStore) GetPinnedPosts(channelId string) (*model. return result, err } -func (s *OpenTracingLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetPrivateChannelsForTeam") s.Root.Store.SetContext(newCtx) @@ -1382,7 +1382,7 @@ func (s *OpenTracingLayerChannelStore) GetPrivateChannelsForTeam(teamId string, return result, err } -func (s *OpenTracingLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetPublicChannelsByIdsForTeam") s.Root.Store.SetContext(newCtx) @@ -1400,7 +1400,7 @@ func (s *OpenTracingLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId stri return result, err } -func (s *OpenTracingLayerChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetPublicChannelsForTeam") s.Root.Store.SetContext(newCtx) @@ -1472,7 +1472,7 @@ func (s *OpenTracingLayerChannelStore) GetSidebarCategoryOrder(userId string, te return result, err } -func (s *OpenTracingLayerChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetTeamChannels") s.Root.Store.SetContext(newCtx) @@ -2170,7 +2170,7 @@ func (s *OpenTracingLayerChannelStore) UpdateSidebarCategoryOrder(userId string, return err } -func (s *OpenTracingLayerChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) *model.AppError { +func (s *OpenTracingLayerChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.UpdateSidebarChannelCategoryOnMove") s.Root.Store.SetContext(newCtx) diff --git a/store/retrylayer/retrylayer.go b/store/retrylayer/retrylayer.go index e831f3ebf8..8c8c9cdee5 100644 --- a/store/retrylayer/retrylayer.go +++ b/store/retrylayer/retrylayer.go @@ -544,9 +544,23 @@ func (s *RetryLayerChannelStore) ClearCaches() { } -func (s *RetryLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) *model.AppError { +func (s *RetryLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) error { - return s.ChannelStore.ClearSidebarOnTeamLeave(userId, teamId) + tries := 0 + for { + err := s.ChannelStore.ClearSidebarOnTeamLeave(userId, teamId) + 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 + } + } } @@ -668,9 +682,23 @@ func (s *RetryLayerChannelStore) Get(id string, allowFromCache bool) (*model.Cha } -func (s *RetryLayerChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError) { +func (s *RetryLayerChannelStore) GetAll(teamId string) ([]*model.Channel, error) { - return s.ChannelStore.GetAll(teamId) + tries := 0 + for { + result, err := s.ChannelStore.GetAll(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 + } + } } @@ -798,9 +826,23 @@ func (s *RetryLayerChannelStore) GetByNames(team_id string, names []string, allo } -func (s *RetryLayerChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) { +func (s *RetryLayerChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, error) { - return s.ChannelStore.GetChannelCounts(teamId, userId) + tries := 0 + for { + result, err := s.ChannelStore.GetChannelCounts(teamId, 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 + } + } } @@ -848,9 +890,23 @@ func (s *RetryLayerChannelStore) GetChannelsBatchForIndexing(startTime int64, en } -func (s *RetryLayerChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, *model.AppError) { +func (s *RetryLayerChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error) { - return s.ChannelStore.GetChannelsByIds(channelIds, includeDeleted) + tries := 0 + for { + result, err := s.ChannelStore.GetChannelsByIds(channelIds, includeDeleted) + 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 + } + } } @@ -900,9 +956,23 @@ func (s *RetryLayerChannelStore) GetDeletedByName(team_id string, name string) ( } -func (s *RetryLayerChannelStore) GetForPost(postId string) (*model.Channel, *model.AppError) { +func (s *RetryLayerChannelStore) GetForPost(postId string) (*model.Channel, error) { - return s.ChannelStore.GetForPost(postId) + tries := 0 + for { + result, err := s.ChannelStore.GetForPost(postId) + 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 + } + } } @@ -1018,21 +1088,63 @@ func (s *RetryLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostLi } -func (s *RetryLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (s *RetryLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) { - return s.ChannelStore.GetPrivateChannelsForTeam(teamId, offset, limit) + tries := 0 + for { + result, err := s.ChannelStore.GetPrivateChannelsForTeam(teamId, offset, limit) + 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 *RetryLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) { +func (s *RetryLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, error) { - return s.ChannelStore.GetPublicChannelsByIdsForTeam(teamId, channelIds) + tries := 0 + for { + result, err := s.ChannelStore.GetPublicChannelsByIdsForTeam(teamId, channelIds) + 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 *RetryLayerChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (s *RetryLayerChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) { - return s.ChannelStore.GetPublicChannelsForTeam(teamId, offset, limit) + tries := 0 + for { + result, err := s.ChannelStore.GetPublicChannelsForTeam(teamId, offset, limit) + 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 + } + } } @@ -1054,9 +1166,23 @@ func (s *RetryLayerChannelStore) GetSidebarCategoryOrder(userId string, teamId s } -func (s *RetryLayerChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) { +func (s *RetryLayerChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, error) { - return s.ChannelStore.GetTeamChannels(teamId) + tries := 0 + for { + result, err := s.ChannelStore.GetTeamChannels(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 + } + } } @@ -1412,9 +1538,23 @@ func (s *RetryLayerChannelStore) UpdateSidebarCategoryOrder(userId string, teamI } -func (s *RetryLayerChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) *model.AppError { +func (s *RetryLayerChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error { - return s.ChannelStore.UpdateSidebarChannelCategoryOnMove(channel, newTeamId) + tries := 0 + for { + err := s.ChannelStore.UpdateSidebarChannelCategoryOnMove(channel, newTeamId) + 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 + } + } } diff --git a/store/searchlayer/channel_layer.go b/store/searchlayer/channel_layer.go index c5ad5f69c7..20fdd9958e 100644 --- a/store/searchlayer/channel_layer.go +++ b/store/searchlayer/channel_layer.go @@ -4,6 +4,8 @@ package searchlayer import ( + "net/http" + "github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/services/searchengine" @@ -164,8 +166,9 @@ func (c *SearchChannelStore) searchAutocompleteChannels(engine searchengine.Sear if len(channelIds) > 0 { channels, err := c.ChannelStore.GetChannelsByIds(channelIds, includeDeleted) if err != nil { - return nil, err + return nil, model.NewAppError("searchAutocompleteChannels", "app.channel.get_channels_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError) } + for _, ch := range channels { channelList = append(channelList, ch) } diff --git a/store/searchlayer/user_layer.go b/store/searchlayer/user_layer.go index dcecc55b59..e30b777da1 100644 --- a/store/searchlayer/user_layer.go +++ b/store/searchlayer/user_layer.go @@ -4,6 +4,8 @@ package searchlayer import ( + "errors" + "net/http" "strings" "github.com/mattermost/mattermost-server/v5/mlog" @@ -166,7 +168,13 @@ func (s *SearchUserStore) getListOfAllowedChannelsForTeam(teamId string, viewRes if teamId != "" && (viewRestrictions == nil || strings.Contains(strings.Join(viewRestrictions.Teams, "."), teamId)) { channels, err := s.rootStore.Channel().GetTeamChannels(teamId) if err != nil { - return nil, err + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("getListOfAllowedChannelsForTeam", "app.channel.get_channels.not_found.app_error", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("getListOfAllowedChannelsForTeam", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + } } for _, channel := range *channels { listOfAllowedChannels = append(listOfAllowedChannels, channel.Id) @@ -177,7 +185,7 @@ func (s *SearchUserStore) getListOfAllowedChannelsForTeam(teamId string, viewRes if len(viewRestrictions.Channels) > 0 { channels, err := s.rootStore.Channel().GetChannelsByIds(viewRestrictions.Channels, false) if err != nil { - return nil, err + return nil, model.NewAppError("getListOfAllowedChannelsForTeam", "app.channel.get_channels_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError) } for _, c := range channels { if teamId == "" || (teamId != "" && c.TeamId == teamId) { diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index e22653f414..ba0374f2c1 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -1085,10 +1085,10 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset in return channels, nil } -func (s SqlChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (s SqlChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) { channels := &model.ChannelList{} - query := s.getQueryBuilder(). + builder := s.getQueryBuilder(). Select("*"). From("Channels"). Where(sq.Eq{"Type": model.CHANNEL_PRIVATE, "TeamId": teamId, "DeleteAt": 0}). @@ -1096,19 +1096,19 @@ func (s SqlChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, li Limit(uint64(limit)). Offset(uint64(offset)) - sql, args, err := query.ToSql() + query, args, err := builder.ToSql() if err != nil { - return nil, model.NewAppError("SqlChannelStore.GetPrivateChannelsForTeam", "store.sql_channel.get_private_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "channels_tosql") } - _, err = s.GetReplica().Select(channels, sql, args...) + _, err = s.GetReplica().Select(channels, query, args...) if err != nil { - return nil, model.NewAppError("SqlChannelStore.GetPrivateChannelsForTeam", "store.sql_channel.get_private_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find chaneld with teamId=%s", teamId) } return channels, nil } -func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) { channels := &model.ChannelList{} _, err := s.GetReplica().Select(channels, ` SELECT @@ -1130,13 +1130,13 @@ func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, lim }) if err != nil { - return nil, model.NewAppError("SqlChannelStore.GetPublicChannelsForTeam", "store.sql_channel.get_public_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find chaneld with teamId=%s", teamId) } return channels, nil } -func (s SqlChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) { +func (s SqlChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, error) { props := make(map[string]interface{}) props["teamId"] = teamId @@ -1167,11 +1167,11 @@ func (s SqlChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds `, props) if err != nil { - return nil, model.NewAppError("SqlChannelStore.GetPublicChannelsByIdsForTeam", "store.sql_channel.get_channels_by_ids.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to find Channels") } if len(*data) == 0 { - return nil, model.NewAppError("SqlChannelStore.GetPublicChannelsByIdsForTeam", "store.sql_channel.get_channels_by_ids.not_found.app_error", nil, "", http.StatusNotFound) + return nil, store.NewErrNotFound("Channel", fmt.Sprintf("teamId=%s, channelIds=%v", teamId, channelIds)) } return data, nil @@ -1183,12 +1183,12 @@ type channelIdWithCountAndUpdateAt struct { UpdateAt int64 } -func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) { +func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, error) { var data []channelIdWithCountAndUpdateAt _, err := s.GetReplica().Select(&data, "SELECT Id, TotalMsgCount, UpdateAt FROM Channels WHERE Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId) AND (TeamId = :TeamId OR TeamId = '') AND DeleteAt = 0 ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId, "UserId": userId}) if err != nil { - return nil, model.NewAppError("SqlChannelStore.GetChannelCounts", "store.sql_channel.get_channel_counts.get.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get channels count with teamId=%s and userId=%s", teamId, userId) } counts := &model.ChannelCounts{Counts: make(map[string]int64), UpdateTimes: make(map[string]int64)} @@ -1201,18 +1201,16 @@ func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model. return counts, nil } -func (s SqlChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) { +func (s SqlChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, error) { data := &model.ChannelList{} _, err := s.GetReplica().Select(data, "SELECT * FROM Channels WHERE TeamId = :TeamId And Type != 'D' ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId}) if err != nil { - // TODO: This error key would go away once this store method is migrated to return plain errors - return nil, model.NewAppError("SqlChannelStore.GetTeamChannels", "app.channel.get_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s", teamId) } if len(*data) == 0 { - // TODO: This error key would go away once this store method is migrated to return plain errors - return nil, model.NewAppError("SqlChannelStore.GetTeamChannels", "app.channel.get_channels.not_found.app_error", nil, "teamId="+teamId, http.StatusNotFound) + return nil, store.NewErrNotFound("Channel", fmt.Sprintf("teamId=%s", teamId)) } return data, nil @@ -2282,18 +2280,18 @@ func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string) return nil } -func (s SqlChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError) { +func (s SqlChannelStore) GetAll(teamId string) ([]*model.Channel, error) { var data []*model.Channel _, err := s.GetReplica().Select(&data, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Type != 'D' ORDER BY Name", map[string]interface{}{"TeamId": teamId}) if err != nil { - return nil, model.NewAppError("SqlChannelStore.GetAll", "store.sql_channel.get_all.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s", teamId) } return data, nil } -func (s SqlChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, *model.AppError) { +func (s SqlChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error) { keys, params := MapStringsToQueryParams(channelIds, "Channel") query := `SELECT * FROM Channels WHERE Id IN ` + keys + ` ORDER BY Name` if !includeDeleted { @@ -2304,13 +2302,12 @@ func (s SqlChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bo _, err := s.GetReplica().Select(&channels, query, params) if err != nil { - mlog.Error("Query error getting channels by ids", mlog.Err(err)) - return nil, model.NewAppError("SqlChannelStore.GetChannelsByIds", "store.sql_channel.get_channels_by_ids.app_error", nil, "", http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to find Channels") } return channels, nil } -func (s SqlChannelStore) GetForPost(postId string) (*model.Channel, *model.AppError) { +func (s SqlChannelStore) GetForPost(postId string) (*model.Channel, error) { channel := &model.Channel{} if err := s.GetReplica().SelectOne( channel, @@ -2322,7 +2319,7 @@ func (s SqlChannelStore) GetForPost(postId string) (*model.Channel, *model.AppEr WHERE Channels.Id = Posts.ChannelId AND Posts.Id = :PostId`, map[string]interface{}{"PostId": postId}); err != nil { - return nil, model.NewAppError("SqlChannelStore.GetForPost", "store.sql_channel.get_for_post.app_error", nil, "postId="+postId+", err="+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get Channel with postId=%s", postId) } return channel, nil diff --git a/store/sqlstore/channel_store_categories.go b/store/sqlstore/channel_store_categories.go index 9e19f5683f..6ac421f267 100644 --- a/store/sqlstore/channel_store_categories.go +++ b/store/sqlstore/channel_store_categories.go @@ -899,15 +899,15 @@ func (s SqlChannelStore) DeleteSidebarChannelsByPreferences(preferences *model.P return nil } -func (s SqlChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) *model.AppError { +func (s SqlChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error { // if channel is being moved, remove it from the categories, since it's possible that there's no matching category in the new team if _, err := s.GetMaster().Exec("DELETE FROM SidebarChannels WHERE ChannelId=:ChannelId", map[string]interface{}{"ChannelId": channel.Id}); err != nil { - return model.NewAppError("SqlChannelStore.UpdateSidebarChannelCategoryOnMove", "store.sql_channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError) + return errors.Wrapf(err, "failed to delete SidebarChannels with channelId=%s", channel.Id) } return nil } -func (s SqlChannelStore) ClearSidebarOnTeamLeave(userId, teamId string) *model.AppError { +func (s SqlChannelStore) ClearSidebarOnTeamLeave(userId, teamId string) error { // if user leaves the team, clean his team related entries in sidebar channels and categories params := map[string]interface{}{ "UserId": userId, @@ -921,10 +921,10 @@ func (s SqlChannelStore) ClearSidebarOnTeamLeave(userId, teamId string) *model.A deleteQuery = "DELETE FROM SidebarChannels USING SidebarChannels AS chan LEFT OUTER JOIN SidebarCategories AS cat ON cat.Id = chan.CategoryId WHERE cat.UserId = :UserId AND cat.TeamId = :TeamId" } if _, err := s.GetMaster().Exec(deleteQuery, params); err != nil { - return model.NewAppError("SqlChannelStore.ClearSidebarOnTeamLeave", "store.sql_channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError) + return errors.Wrap(err, "failed to delete from SidebarChannels") } if _, err := s.GetMaster().Exec("DELETE FROM SidebarCategories WHERE SidebarCategories.TeamId = :TeamId AND SidebarCategories.UserId = :UserId", params); err != nil { - return model.NewAppError("SqlChannelStore.ClearSidebarOnTeamLeave", "store.sql_channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError) + return errors.Wrap(err, "failed to delete from SidebarCategories") } return nil } diff --git a/store/store.go b/store/store.go index 133acbd044..56098e34c5 100644 --- a/store/store.go +++ b/store/store.go @@ -134,8 +134,8 @@ type ChannelStore interface { CreateDirectChannel(userId *model.User, otherUserId *model.User) (*model.Channel, error) SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, error) Update(channel *model.Channel) (*model.Channel, error) - UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) *model.AppError - ClearSidebarOnTeamLeave(userId, teamId string) *model.AppError + UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error + ClearSidebarOnTeamLeave(userId, teamId string) error Get(id string, allowFromCache bool) (*model.Channel, error) InvalidateChannel(id string) InvalidateChannelByName(teamId, name string) @@ -154,14 +154,14 @@ type ChannelStore interface { GetAllChannels(page, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, error) GetAllChannelsCount(opts ChannelSearchOpts) (int64, error) GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, error) - GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) - GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) - GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) - GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) - GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) - GetAll(teamId string) ([]*model.Channel, *model.AppError) - GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, *model.AppError) - GetForPost(postId string) (*model.Channel, *model.AppError) + GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) + GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) + GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, error) + GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, error) + GetTeamChannels(teamId string) (*model.ChannelList, error) + GetAll(teamId string) ([]*model.Channel, error) + GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error) + GetForPost(postId string) (*model.Channel, error) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) SaveMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index 25fb3baf76..20ea05a273 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -3773,7 +3773,8 @@ func testChannelStoreGetPublicChannelsByIdsForTeam(t *testing.T, ss store.Store) t.Run("random channel id should not be found as a public channel in the team", func(t *testing.T) { _, err := ss.Channel().GetPublicChannelsByIdsForTeam(teamId, []string{model.NewId()}) require.NotNil(t, err) - require.Equal(t, "store.sql_channel.get_channels_by_ids.not_found.app_error", err.Id) + var nfErr *store.ErrNotFound + require.True(t, errors.As(err, &nfErr)) }) } diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index b3267a03a1..04531e0fe1 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -133,16 +133,14 @@ func (_m *ChannelStore) ClearCaches() { } // ClearSidebarOnTeamLeave provides a mock function with given fields: userId, teamId -func (_m *ChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) *model.AppError { +func (_m *ChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) error { ret := _m.Called(userId, teamId) - var r0 *model.AppError - if rf, ok := ret.Get(0).(func(string, string) *model.AppError); ok { + var r0 error + if rf, ok := ret.Get(0).(func(string, string) error); ok { r0 = rf(userId, teamId) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } + r0 = ret.Error(0) } return r0 @@ -301,7 +299,7 @@ func (_m *ChannelStore) Get(id string, allowFromCache bool) (*model.Channel, err } // GetAll provides a mock function with given fields: teamId -func (_m *ChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError) { +func (_m *ChannelStore) GetAll(teamId string) ([]*model.Channel, error) { ret := _m.Called(teamId) var r0 []*model.Channel @@ -313,13 +311,11 @@ func (_m *ChannelStore) GetAll(teamId string) ([]*model.Channel, *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(teamId) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 @@ -539,7 +535,7 @@ func (_m *ChannelStore) GetByNames(team_id string, names []string, allowFromCach } // GetChannelCounts provides a mock function with given fields: teamId, userId -func (_m *ChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) { +func (_m *ChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, error) { ret := _m.Called(teamId, userId) var r0 *model.ChannelCounts @@ -551,13 +547,11 @@ func (_m *ChannelStore) GetChannelCounts(teamId string, userId string) (*model.C } } - 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, userId) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 @@ -687,7 +681,7 @@ func (_m *ChannelStore) GetChannelsBatchForIndexing(startTime int64, endTime int } // GetChannelsByIds provides a mock function with given fields: channelIds, includeDeleted -func (_m *ChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, *model.AppError) { +func (_m *ChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error) { ret := _m.Called(channelIds, includeDeleted) var r0 []*model.Channel @@ -699,13 +693,11 @@ func (_m *ChannelStore) GetChannelsByIds(channelIds []string, includeDeleted boo } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func([]string, bool) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func([]string, bool) error); ok { r1 = rf(channelIds, includeDeleted) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 @@ -783,7 +775,7 @@ func (_m *ChannelStore) GetDeletedByName(team_id string, name string) (*model.Ch } // GetForPost provides a mock function with given fields: postId -func (_m *ChannelStore) GetForPost(postId string) (*model.Channel, *model.AppError) { +func (_m *ChannelStore) GetForPost(postId string) (*model.Channel, error) { ret := _m.Called(postId) var r0 *model.Channel @@ -795,13 +787,11 @@ func (_m *ChannelStore) GetForPost(postId string) (*model.Channel, *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(postId) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 @@ -1137,7 +1127,7 @@ func (_m *ChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *mode } // GetPrivateChannelsForTeam provides a mock function with given fields: teamId, offset, limit -func (_m *ChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (_m *ChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) { ret := _m.Called(teamId, offset, limit) var r0 *model.ChannelList @@ -1149,20 +1139,18 @@ func (_m *ChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, lim } } - 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(teamId, offset, limit) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetPublicChannelsByIdsForTeam provides a mock function with given fields: teamId, channelIds -func (_m *ChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) { +func (_m *ChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, error) { ret := _m.Called(teamId, channelIds) var r0 *model.ChannelList @@ -1174,20 +1162,18 @@ func (_m *ChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds } } - 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, channelIds) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetPublicChannelsForTeam provides a mock function with given fields: teamId, offset, limit -func (_m *ChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (_m *ChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) { ret := _m.Called(teamId, offset, limit) var r0 *model.ChannelList @@ -1199,13 +1185,11 @@ func (_m *ChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limi } } - 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(teamId, offset, limit) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 @@ -1287,7 +1271,7 @@ func (_m *ChannelStore) GetSidebarCategoryOrder(userId string, teamId string) ([ } // GetTeamChannels provides a mock function with given fields: teamId -func (_m *ChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) { +func (_m *ChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, error) { ret := _m.Called(teamId) var r0 *model.ChannelList @@ -1299,13 +1283,11 @@ func (_m *ChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *mod } } - 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 @@ -2024,16 +2006,14 @@ func (_m *ChannelStore) UpdateSidebarCategoryOrder(userId string, teamId string, } // UpdateSidebarChannelCategoryOnMove provides a mock function with given fields: channel, newTeamId -func (_m *ChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) *model.AppError { +func (_m *ChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error { ret := _m.Called(channel, newTeamId) - var r0 *model.AppError - if rf, ok := ret.Get(0).(func(*model.Channel, string) *model.AppError); ok { + var r0 error + if rf, ok := ret.Get(0).(func(*model.Channel, string) error); ok { r0 = rf(channel, newTeamId) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } + r0 = ret.Error(0) } return r0 diff --git a/store/timerlayer/timerlayer.go b/store/timerlayer/timerlayer.go index 7d3551ba88..46881f0d39 100644 --- a/store/timerlayer/timerlayer.go +++ b/store/timerlayer/timerlayer.go @@ -553,7 +553,7 @@ func (s *TimerLayerChannelStore) ClearCaches() { } } -func (s *TimerLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) *model.AppError { +func (s *TimerLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) error { start := timemodule.Now() err := s.ChannelStore.ClearSidebarOnTeamLeave(userId, teamId) @@ -697,7 +697,7 @@ func (s *TimerLayerChannelStore) Get(id string, allowFromCache bool) (*model.Cha return result, err } -func (s *TimerLayerChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError) { +func (s *TimerLayerChannelStore) GetAll(teamId string) ([]*model.Channel, error) { start := timemodule.Now() result, err := s.ChannelStore.GetAll(teamId) @@ -857,7 +857,7 @@ func (s *TimerLayerChannelStore) GetByNames(team_id string, names []string, allo return result, err } -func (s *TimerLayerChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) { +func (s *TimerLayerChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, error) { start := timemodule.Now() result, err := s.ChannelStore.GetChannelCounts(teamId, userId) @@ -953,7 +953,7 @@ func (s *TimerLayerChannelStore) GetChannelsBatchForIndexing(startTime int64, en return result, err } -func (s *TimerLayerChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, *model.AppError) { +func (s *TimerLayerChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error) { start := timemodule.Now() result, err := s.ChannelStore.GetChannelsByIds(channelIds, includeDeleted) @@ -1017,7 +1017,7 @@ func (s *TimerLayerChannelStore) GetDeletedByName(team_id string, name string) ( return result, err } -func (s *TimerLayerChannelStore) GetForPost(postId string) (*model.Channel, *model.AppError) { +func (s *TimerLayerChannelStore) GetForPost(postId string) (*model.Channel, error) { start := timemodule.Now() result, err := s.ChannelStore.GetForPost(postId) @@ -1257,7 +1257,7 @@ func (s *TimerLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostLi return result, err } -func (s *TimerLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (s *TimerLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) { start := timemodule.Now() result, err := s.ChannelStore.GetPrivateChannelsForTeam(teamId, offset, limit) @@ -1273,7 +1273,7 @@ func (s *TimerLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset return result, err } -func (s *TimerLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) { +func (s *TimerLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, error) { start := timemodule.Now() result, err := s.ChannelStore.GetPublicChannelsByIdsForTeam(teamId, channelIds) @@ -1289,7 +1289,7 @@ func (s *TimerLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, ch return result, err } -func (s *TimerLayerChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (s *TimerLayerChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) { start := timemodule.Now() result, err := s.ChannelStore.GetPublicChannelsForTeam(teamId, offset, limit) @@ -1353,7 +1353,7 @@ func (s *TimerLayerChannelStore) GetSidebarCategoryOrder(userId string, teamId s return result, err } -func (s *TimerLayerChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) { +func (s *TimerLayerChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, error) { start := timemodule.Now() result, err := s.ChannelStore.GetTeamChannels(teamId) @@ -2002,7 +2002,7 @@ func (s *TimerLayerChannelStore) UpdateSidebarCategoryOrder(userId string, teamI return err } -func (s *TimerLayerChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) *model.AppError { +func (s *TimerLayerChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error { start := timemodule.Now() err := s.ChannelStore.UpdateSidebarChannelCategoryOnMove(channel, newTeamId)