From 6e92b76932a1f8007992c2d3729453601f7fd8d9 Mon Sep 17 00:00:00 2001 From: Mohammed Salman Date: Mon, 7 Dec 2020 12:45:17 +0300 Subject: [PATCH] Remove model.AppError from searchlayer/channel_layer.go (#16428) Automatic Merge --- store/searchlayer/channel_layer.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/store/searchlayer/channel_layer.go b/store/searchlayer/channel_layer.go index aae10e087c..4db1c977b2 100644 --- a/store/searchlayer/channel_layer.go +++ b/store/searchlayer/channel_layer.go @@ -4,12 +4,11 @@ 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" "github.com/mattermost/mattermost-server/v5/store" + "github.com/pkg/errors" ) type SearchChannelStore struct { @@ -130,15 +129,14 @@ func (c *SearchChannelStore) SaveDirectChannel(directchannel *model.Channel, mem func (c *SearchChannelStore) AutocompleteInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, error) { var channelList *model.ChannelList - var appErr *model.AppError - var nErr error + var err error allFailed := true for _, engine := range c.rootStore.searchEngine.GetActiveEngines() { if engine.IsAutocompletionEnabled() { - channelList, appErr = c.searchAutocompleteChannels(engine, teamId, term, includeDeleted) - if appErr != nil { - mlog.Error("Encountered error on AutocompleteChannels through SearchEngine. Falling back to default autocompletion.", mlog.String("search_engine", engine.GetName()), mlog.Err(appErr)) + channelList, err = c.searchAutocompleteChannels(engine, teamId, term, includeDeleted) + if err != nil { + mlog.Error("Encountered error on AutocompleteChannels through SearchEngine. Falling back to default autocompletion.", mlog.String("search_engine", engine.GetName()), mlog.Err(err)) continue } allFailed = false @@ -149,20 +147,20 @@ func (c *SearchChannelStore) AutocompleteInTeam(teamId string, term string, incl if allFailed { mlog.Debug("Using database search because no other search engine is available") - channelList, nErr = c.ChannelStore.AutocompleteInTeam(teamId, term, includeDeleted) - if nErr != nil { - return nil, model.NewAppError("AutocompleteInTeam", "app.channel.search.app_error", nil, nErr.Error(), http.StatusInternalServerError) + channelList, err = c.ChannelStore.AutocompleteInTeam(teamId, term, includeDeleted) + if err != nil { + return nil, errors.Wrap(err, "Failed to autocomplete channels in team") } } - if appErr != nil { - return channelList, appErr + if err != nil { + return channelList, err } return channelList, nil } -func (c *SearchChannelStore) searchAutocompleteChannels(engine searchengine.SearchEngineInterface, teamId, term string, includeDeleted bool) (*model.ChannelList, *model.AppError) { +func (c *SearchChannelStore) searchAutocompleteChannels(engine searchengine.SearchEngineInterface, teamId, term string, includeDeleted bool) (*model.ChannelList, error) { channelIds, err := engine.SearchChannels(teamId, term) if err != nil { return nil, err @@ -172,7 +170,7 @@ func (c *SearchChannelStore) searchAutocompleteChannels(engine searchengine.Sear if len(channelIds) > 0 { channels, err := c.ChannelStore.GetChannelsByIds(channelIds, includeDeleted) if err != nil { - return nil, model.NewAppError("searchAutocompleteChannels", "app.channel.get_channels_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "Failed to get channels by ids") } for _, ch := range channels {