diff --git a/app/channel.go b/app/channel.go index 78510175ca..17d089a945 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1619,7 +1619,11 @@ func (a *App) GetDeletedChannels(teamId string, offset int, limit int, userId st } func (a *App) GetChannelsUserNotIn(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) { - return a.Srv().Store.Channel().GetMoreChannels(teamId, userId, offset, limit) + channels, err := a.Srv().Store.Channel().GetMoreChannels(teamId, userId, offset, limit) + if err != nil { + return nil, model.NewAppError("GetChannelsUserNotIn", "app.channel.get_more_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + } + return channels, nil } func (a *App) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) { diff --git a/i18n/en.json b/i18n/en.json index 5fb4195e25..5ffa61932d 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -3046,6 +3046,10 @@ "id": "app.channel.get_deleted.missing.app_error", "translation": "No deleted channels exist." }, + { + "id": "app.channel.get_more_channels.get.app_error", + "translation": "Unable to get the 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." @@ -6246,10 +6250,6 @@ "id": "store.sql_channel.get_members_by_ids.app_error", "translation": "Unable to get the channel members." }, - { - "id": "store.sql_channel.get_more_channels.get.app_error", - "translation": "Unable to get the channels." - }, { "id": "store.sql_channel.get_pinnedpost_count.app_error", "translation": "Unable to get the channel pinned post count." diff --git a/store/opentracing_layer.go b/store/opentracing_layer.go index 16c30fadba..b823938088 100644 --- a/store/opentracing_layer.go +++ b/store/opentracing_layer.go @@ -1219,7 +1219,7 @@ func (s *OpenTracingLayerChannelStore) GetMembersForUserWithPagination(teamId st return resultVar0, resultVar1 } -func (s *OpenTracingLayerChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMoreChannels") s.Root.Store.SetContext(newCtx) diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index 7ea32fda1f..a0e15234be 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -999,7 +999,7 @@ func (s SqlChannelStore) getAllChannelsQuery(opts store.ChannelSearchOpts, forCo return query } -func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, error) { channels := &model.ChannelList{} _, err := s.GetReplica().Select(channels, ` SELECT @@ -1035,7 +1035,7 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset in }) if err != nil { - return nil, model.NewAppError("SqlChannelStore.GetMoreChannels", "store.sql_channel.get_more_channels.get.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed getting channels with teamId=%s and userId=%s", teamId, userId) } return channels, nil diff --git a/store/store.go b/store/store.go index 18ee413497..84fb674bb2 100644 --- a/store/store.go +++ b/store/store.go @@ -151,7 +151,7 @@ type ChannelStore interface { GetChannels(teamId string, userId string, includeDeleted bool) (*model.ChannelList, error) 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, *model.AppError) + GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, error) 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) diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index 8dc157d5ae..cc044c070f 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -614,8 +614,8 @@ func testChannelStoreDelete(t *testing.T, ss store.Store) { require.Nil(t, nErr) require.Len(t, *list, 1, "invalid number of channels") - list, err = ss.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 0, 100) - require.Nil(t, err) + list, nErr = ss.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 0, 100) + require.Nil(t, nErr) require.Len(t, *list, 1, "invalid number of channels") cresult := ss.Channel().PermanentDelete(o2.Id) diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index a5d3a9397e..aeffdb9c7b 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -981,7 +981,7 @@ func (_m *ChannelStore) GetMembersForUserWithPagination(teamId string, userId st } // GetMoreChannels provides a mock function with given fields: teamId, userId, offset, limit -func (_m *ChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (_m *ChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, error) { ret := _m.Called(teamId, userId, offset, limit) var r0 *model.ChannelList @@ -993,13 +993,11 @@ func (_m *ChannelStore) GetMoreChannels(teamId string, userId string, offset int } } - 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, userId, offset, limit) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 diff --git a/store/timer_layer.go b/store/timer_layer.go index 2bdb26e37a..b6e06bb830 100644 --- a/store/timer_layer.go +++ b/store/timer_layer.go @@ -1128,7 +1128,7 @@ func (s *TimerLayerChannelStore) GetMembersForUserWithPagination(teamId string, return resultVar0, resultVar1 } -func (s *TimerLayerChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) { +func (s *TimerLayerChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, error) { start := timemodule.Now() resultVar0, resultVar1 := s.ChannelStore.GetMoreChannels(teamId, userId, offset, limit)