diff --git a/api4/channel.go b/api4/channel.go index ba8cdc4914..4b7810daeb 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -1052,7 +1052,7 @@ func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) { } } else { if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_READ_CHANNEL) { - c.Err = model.NewAppError("getChannelByName", store.MISSING_CHANNEL_ERROR, nil, "teamId="+channel.TeamId+", "+"name="+channel.Name+"", http.StatusNotFound) + c.Err = model.NewAppError("getChannelByName", "app.channel.get_by_name.missing.app_error", nil, "teamId="+channel.TeamId+", "+"name="+channel.Name+"", http.StatusNotFound) return } } @@ -1080,7 +1080,7 @@ func getChannelByNameForTeamName(c *Context, w http.ResponseWriter, r *http.Requ } if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_READ_CHANNEL) { - c.Err = model.NewAppError("getChannelByNameForTeamName", store.MISSING_CHANNEL_ERROR, nil, "teamId="+channel.TeamId+", "+"name="+channel.Name+"", http.StatusNotFound) + c.Err = model.NewAppError("getChannelByNameForTeamName", "app.channel.get_by_name.missing.app_error", nil, "teamId="+channel.TeamId+", "+"name="+channel.Name+"", http.StatusNotFound) return } diff --git a/app/channel.go b/app/channel.go index 4efc3219ef..78510175ca 100644 --- a/app/channel.go +++ b/app/channel.go @@ -77,7 +77,13 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin for _, channelName := range a.DefaultChannelNames() { channel, channelErr := a.Srv().Store.Channel().GetByName(teamId, channelName, true) if channelErr != nil { - err = channelErr + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + err = model.NewAppError("JoinDefaultChannels", "app.channel.get_by_name.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + default: + err = model.NewAppError("JoinDefaultChannels", "app.channel.get_by_name.existing.app_error", nil, err.Error(), http.StatusInternalServerError) + } continue } @@ -273,9 +279,11 @@ func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Chan } func (a *App) GetOrCreateDirectChannel(userId, otherUserId string) (*model.Channel, *model.AppError) { - channel, err := a.Srv().Store.Channel().GetByName("", model.GetDMNameFromIds(userId, otherUserId), true) - if err != nil { - if err.Id == store.MISSING_CHANNEL_ERROR { + channel, nErr := a.Srv().Store.Channel().GetByName("", model.GetDMNameFromIds(userId, otherUserId), true) + if nErr != nil { + var nfErr *store.ErrNotFound + if errors.As(nErr, &nfErr) { + var err *model.AppError channel, err = a.createDirectChannel(userId, otherUserId) if err != nil { if err.Id == store.CHANNEL_EXISTS_ERROR { @@ -305,7 +313,7 @@ func (a *App) GetOrCreateDirectChannel(userId, otherUserId string) (*model.Chann return channel, nil } - return nil, model.NewAppError("GetOrCreateDMChannel", "web.incoming_webhook.channel.app_error", nil, "err="+err.Message, err.StatusCode) + return nil, model.NewAppError("GetOrCreateDirectChannel", "web.incoming_webhook.channel.app_error", nil, nErr.Error(), http.StatusInternalServerError) } return channel, nil } @@ -1486,7 +1494,7 @@ func (a *App) GetChannel(channelId string) (*model.Channel, *model.AppError) { func (a *App) GetChannelByName(channelName, teamId string, includeDeleted bool) (*model.Channel, *model.AppError) { var channel *model.Channel - var err *model.AppError + var err error if includeDeleted { channel, err = a.Srv().Store.Channel().GetByNameIncludeDeleted(teamId, channelName, false) @@ -1494,14 +1502,14 @@ func (a *App) GetChannelByName(channelName, teamId string, includeDeleted bool) channel, err = a.Srv().Store.Channel().GetByName(teamId, channelName, false) } - if err != nil && err.Id == "store.sql_channel.get_by_name.missing.app_error" { - err.StatusCode = http.StatusNotFound - return nil, err - } - if err != nil { - err.StatusCode = http.StatusBadRequest - return nil, err + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("GetChannelByName", "app.channel.get_by_name.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("GetChannelByName", "app.channel.get_by_name.existing.app_error", nil, err.Error(), http.StatusInternalServerError) + } } return channel, nil @@ -1510,12 +1518,7 @@ func (a *App) GetChannelByName(channelName, teamId string, includeDeleted bool) func (a *App) GetChannelsByNames(channelNames []string, teamId string) ([]*model.Channel, *model.AppError) { channels, err := a.Srv().Store.Channel().GetByNames(teamId, channelNames, true) if err != nil { - if err.Id == "store.sql_channel.get_by_name.missing.app_error" { - err.StatusCode = http.StatusNotFound - return nil, err - } - err.StatusCode = http.StatusBadRequest - return nil, err + return nil, model.NewAppError("GetChannelsByNames", "app.channel.get_by_name.existing.app_error", nil, err.Error(), http.StatusInternalServerError) } return channels, nil } @@ -1531,20 +1534,21 @@ func (a *App) GetChannelByNameForTeamName(channelName, teamName string, includeD var result *model.Channel + var nErr error if includeDeleted { - result, err = a.Srv().Store.Channel().GetByNameIncludeDeleted(team.Id, channelName, false) + result, nErr = a.Srv().Store.Channel().GetByNameIncludeDeleted(team.Id, channelName, false) } else { - result, err = a.Srv().Store.Channel().GetByName(team.Id, channelName, false) + result, nErr = a.Srv().Store.Channel().GetByName(team.Id, channelName, false) } - if err != nil && err.Id == "store.sql_channel.get_by_name.missing.app_error" { - err.StatusCode = http.StatusNotFound - return nil, err - } - - if err != nil { - err.StatusCode = http.StatusBadRequest - return nil, err + if nErr != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(nErr, &nfErr): + return nil, model.NewAppError("GetChannelByNameForTeamName", "app.channel.get_by_name.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("GetChannelByNameForTeamName", "app.channel.get_by_name.existing.app_error", nil, nErr.Error(), http.StatusInternalServerError) + } } return result, nil diff --git a/app/command_join.go b/app/command_join.go index aa5c805ccc..fe8a46c910 100644 --- a/app/command_join.go +++ b/app/command_join.go @@ -7,7 +7,6 @@ import ( "strings" goi18n "github.com/mattermost/go-i18n/i18n" - "github.com/mattermost/mattermost-server/v5/model" ) @@ -65,12 +64,12 @@ func (me *JoinProvider) DoCommand(a *App, args *model.CommandArgs, message strin return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } - if err = a.JoinChannel(channel, args.UserId); err != nil { + if appErr := a.JoinChannel(channel, args.UserId); appErr != nil { return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } - team, err := a.GetTeam(channel.TeamId) - if err != nil { + team, appErr := a.GetTeam(channel.TeamId) + if appErr != nil { return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } diff --git a/app/command_msg.go b/app/command_msg.go index 771133e895..5ef2737fa7 100644 --- a/app/command_msg.go +++ b/app/command_msg.go @@ -4,11 +4,13 @@ package app import ( + "errors" "strings" goi18n "github.com/mattermost/go-i18n/i18n" "github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/model" + "github.com/mattermost/mattermost-server/v5/store" ) type msgProvider struct { @@ -72,7 +74,8 @@ func (me *msgProvider) DoCommand(a *App, args *model.CommandArgs, message string targetChannelId := "" if channel, channelErr := a.Srv().Store.Channel().GetByName(args.TeamId, channelName, true); channelErr != nil { - if channelErr.Id == "store.sql_channel.get_by_name.missing.app_error" { + var nfErr *store.ErrNotFound + if errors.As(channelErr, &nfErr) { if !a.SessionHasPermissionTo(args.Session, model.PERMISSION_CREATE_DIRECT_CHANNEL) { return &model.CommandResponse{Text: args.T("api.command_msg.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } diff --git a/app/import_functions.go b/app/import_functions.go index be31f08a23..ec28c8d2d4 100644 --- a/app/import_functions.go +++ b/app/import_functions.go @@ -1150,7 +1150,7 @@ func (a *App) getChannelsForPosts(teams map[string]*model.Team, data []*PostImpo for _, postData := range data { team := teams[*postData.Team] if channel, ok := channels[*postData.Channel]; !ok || channel == nil { - var err *model.AppError + var err error channel, err = a.Srv().Store.Channel().GetByName(team.Id, *postData.Channel, true) if err != nil { return nil, model.NewAppError("BulkImport", "app.import.import_post.channel_not_found.error", map[string]interface{}{"ChannelName": *postData.Channel}, err.Error(), http.StatusBadRequest) diff --git a/app/slackimport.go b/app/slackimport.go index 75c64c0130..2903a5b34e 100644 --- a/app/slackimport.go +++ b/app/slackimport.go @@ -532,7 +532,7 @@ func (a *App) SlackAddChannels(teamId string, slackchannels []SlackChannel, post newChannel = SlackSanitiseChannelProperties(newChannel) var mChannel *model.Channel - var err *model.AppError + var err error if mChannel, err = a.Srv().Store.Channel().GetByName(teamId, sChannel.Name, true); err == nil { // The channel already exists as an active channel. Merge with the existing one. importerLog.WriteString(utils.T("api.slackimport.slack_add_channels.merge", map[string]interface{}{"DisplayName": newChannel.DisplayName})) diff --git a/app/team.go b/app/team.go index 67ede75502..dd2c3aac4b 100644 --- a/app/team.go +++ b/app/team.go @@ -1008,9 +1008,15 @@ func (a *App) LeaveTeam(team *model.Team, user *model.User, requestorId string) } } - channel, err := a.Srv().Store.Channel().GetByName(team.Id, model.DEFAULT_CHANNEL, false) - if err != nil { - return err + channel, nErr := a.Srv().Store.Channel().GetByName(team.Id, model.DEFAULT_CHANNEL, false) + if nErr != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(nErr, &nfErr): + return model.NewAppError("LeaveTeam", "app.channel.get_by_name.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + default: + return model.NewAppError("LeaveTeam", "app.channel.get_by_name.existing.app_error", nil, nErr.Error(), http.StatusInternalServerError) + } } if *a.Config().ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages { diff --git a/app/webhook.go b/app/webhook.go index 46989d34c5..65a0cf30a5 100644 --- a/app/webhook.go +++ b/app/webhook.go @@ -628,14 +628,14 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq cchan = make(chan store.StoreResult, 1) go func() { chnn, chnnErr := a.Srv().Store.Channel().GetByName(hook.TeamId, channelName[1:], true) - cchan <- store.StoreResult{Data: chnn, Err: chnnErr} + cchan <- store.StoreResult{Data: chnn, NErr: chnnErr} close(cchan) }() } else { cchan = make(chan store.StoreResult, 1) go func() { chnn, chnnErr := a.Srv().Store.Channel().GetByName(hook.TeamId, channelName, true) - cchan <- store.StoreResult{Data: chnn, Err: chnnErr} + cchan <- store.StoreResult{Data: chnn, NErr: chnnErr} close(cchan) }() } @@ -655,8 +655,14 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq if channel == nil { result := <-cchan - if result.Err != nil { - return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+result.Err.Message, result.Err.StatusCode) + if result.NErr != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(result.NErr, &nfErr): + return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, nfErr.Error(), http.StatusNotFound) + default: + return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + } } else { channel = result.Data.(*model.Channel) } diff --git a/i18n/en.json b/i18n/en.json index 44419387a3..41e6e6ddba 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -3014,6 +3014,14 @@ "id": "app.channel.get_all_channels_count.app_error", "translation": "Unable to count all the channels." }, + { + "id": "app.channel.get_by_name.existing.app_error", + "translation": "Unable to find the existing channel." + }, + { + "id": "app.channel.get_by_name.missing.app_error", + "translation": "Channel does not exist." + }, { "id": "app.channel.get_channels.get.app_error", "translation": "Unable to get the channels." @@ -6162,14 +6170,6 @@ "id": "store.sql_channel.get_all_direct.app_error", "translation": "Unable to get all the direct channels." }, - { - "id": "store.sql_channel.get_by_name.existing.app_error", - "translation": "Unable to find the existing channel." - }, - { - "id": "store.sql_channel.get_by_name.missing.app_error", - "translation": "Channel does not exist." - }, { "id": "store.sql_channel.get_by_scheme.app_error", "translation": "Unable to get the channels for the provided scheme." diff --git a/store/constants.go b/store/constants.go index a9f9a4f8d9..a4ff445303 100644 --- a/store/constants.go +++ b/store/constants.go @@ -4,7 +4,6 @@ package store const ( - MISSING_CHANNEL_ERROR = "store.sql_channel.get_by_name.missing.app_error" MISSING_CHANNEL_MEMBER_ERROR = "store.sql_channel.get_member.missing.app_error" CHANNEL_EXISTS_ERROR = "store.sql_channel.save_channel.exists.app_error" diff --git a/store/opentracing_layer.go b/store/opentracing_layer.go index 9cce851fac..bdd334ab1f 100644 --- a/store/opentracing_layer.go +++ b/store/opentracing_layer.go @@ -774,7 +774,7 @@ func (s *OpenTracingLayerChannelStore) GetAllDirectChannelsForExportAfter(limit return resultVar0, resultVar1 } -func (s *OpenTracingLayerChannelStore) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetByName") s.Root.Store.SetContext(newCtx) @@ -792,7 +792,7 @@ func (s *OpenTracingLayerChannelStore) GetByName(team_id string, name string, al return resultVar0, resultVar1 } -func (s *OpenTracingLayerChannelStore) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetByNameIncludeDeleted") s.Root.Store.SetContext(newCtx) @@ -810,7 +810,7 @@ func (s *OpenTracingLayerChannelStore) GetByNameIncludeDeleted(team_id string, n return resultVar0, resultVar1 } -func (s *OpenTracingLayerChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetByNames") s.Root.Store.SetContext(newCtx) diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index b12e18a6dc..f56ca004e1 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -1151,11 +1151,11 @@ func (s SqlChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *mo return data, nil } -func (s SqlChannelStore) GetByName(teamId string, name string, allowFromCache bool) (*model.Channel, *model.AppError) { +func (s SqlChannelStore) GetByName(teamId string, name string, allowFromCache bool) (*model.Channel, error) { return s.getByName(teamId, name, false, allowFromCache) } -func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) { +func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCache bool) ([]*model.Channel, error) { var channels []*model.Channel if allowFromCache { @@ -1195,7 +1195,11 @@ func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCach var dbChannels []*model.Channel if _, err := s.GetReplica().Select(&dbChannels, query, props); err != nil && err != sql.ErrNoRows { - return nil, model.NewAppError("SqlChannelStore.GetByName", "store.sql_channel.get_by_name.existing.app_error", nil, "teamId="+teamId+", "+err.Error(), http.StatusInternalServerError) + msg := fmt.Sprintf("failed to get channels with names=%v", names) + if teamId != "" { + msg += fmt.Sprintf("teamId=%s", teamId) + } + return nil, errors.Wrap(err, msg) } for _, channel := range dbChannels { channelByNameCache.SetWithExpiry(teamId+channel.Name, channel, CHANNEL_CACHE_DURATION) @@ -1215,11 +1219,11 @@ func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCach return channels, nil } -func (s SqlChannelStore) GetByNameIncludeDeleted(teamId string, name string, allowFromCache bool) (*model.Channel, *model.AppError) { +func (s SqlChannelStore) GetByNameIncludeDeleted(teamId string, name string, allowFromCache bool) (*model.Channel, error) { return s.getByName(teamId, name, true, allowFromCache) } -func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bool, allowFromCache bool) (*model.Channel, *model.AppError) { +func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bool, allowFromCache bool) (*model.Channel, error) { var query string if includeDeleted { query = "SELECT * FROM Channels WHERE (TeamId = :TeamId OR TeamId = '') AND Name = :Name" @@ -1243,9 +1247,9 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo if err := s.GetReplica().SelectOne(&channel, query, map[string]interface{}{"TeamId": teamId, "Name": name}); err != nil { if err == sql.ErrNoRows { - return nil, model.NewAppError("SqlChannelStore.GetByName", store.MISSING_CHANNEL_ERROR, nil, "teamId="+teamId+", "+"name="+name+"", http.StatusNotFound) + return nil, store.NewErrNotFound("Channel", fmt.Sprintf("TeamId=%s&Name=%s", teamId, name)) } - return nil, model.NewAppError("SqlChannelStore.GetByName", "store.sql_channel.get_by_name.existing.app_error", nil, "teamId="+teamId+", "+"name="+name+", "+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find channel with TeamId=%s and Name=%s", teamId, name) } channelByNameCache.SetWithExpiry(teamId+name, &channel, CHANNEL_CACHE_DURATION) diff --git a/store/store.go b/store/store.go index 79dc7513ba..f98dd4d7b4 100644 --- a/store/store.go +++ b/store/store.go @@ -143,9 +143,9 @@ type ChannelStore interface { SetDeleteAt(channelId string, deleteAt int64, updateAt int64) error PermanentDelete(channelId string) error PermanentDeleteByTeam(teamId string) error - GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) - GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) - GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) + GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, error) + GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error) + GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, error) GetDeletedByName(team_id string, name string) (*model.Channel, *model.AppError) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, error) GetChannels(teamId string, userId string, includeDeleted bool) (*model.ChannelList, error) diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index 4614c6e5af..69c1d46697 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -714,8 +714,8 @@ func testChannelStoreGetByNames(t *testing.T, ss store.Store) { err = ss.Channel().Delete(o2.Id, model.GetMillis()) require.Nil(t, err, "channel should have been deleted") - channels, err := ss.Channel().GetByNames(o1.TeamId, []string{o1.Name}, false) - require.Nil(t, err) + channels, nErr := ss.Channel().GetByNames(o1.TeamId, []string{o1.Name}, false) + require.Nil(t, nErr) assert.Empty(t, channels) } diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index 9959521e42..9725d1dd8a 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -385,7 +385,7 @@ func (_m *ChannelStore) GetAllDirectChannelsForExportAfter(limit int, afterId st } // GetByName provides a mock function with given fields: team_id, name, allowFromCache -func (_m *ChannelStore) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) { +func (_m *ChannelStore) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, error) { ret := _m.Called(team_id, name, allowFromCache) var r0 *model.Channel @@ -397,20 +397,18 @@ func (_m *ChannelStore) GetByName(team_id string, name string, allowFromCache bo } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, string, bool) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, string, bool) error); ok { r1 = rf(team_id, name, allowFromCache) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetByNameIncludeDeleted provides a mock function with given fields: team_id, name, allowFromCache -func (_m *ChannelStore) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) { +func (_m *ChannelStore) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, error) { ret := _m.Called(team_id, name, allowFromCache) var r0 *model.Channel @@ -422,20 +420,18 @@ func (_m *ChannelStore) GetByNameIncludeDeleted(team_id string, name string, all } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, string, bool) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, string, bool) error); ok { r1 = rf(team_id, name, allowFromCache) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetByNames provides a mock function with given fields: team_id, names, allowFromCache -func (_m *ChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) { +func (_m *ChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error) { ret := _m.Called(team_id, names, allowFromCache) var r0 []*model.Channel @@ -447,13 +443,11 @@ func (_m *ChannelStore) GetByNames(team_id string, names []string, allowFromCach } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, []string, bool) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, []string, bool) error); ok { r1 = rf(team_id, names, allowFromCache) } 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 ce6398adf8..3bcbcc556c 100644 --- a/store/timer_layer.go +++ b/store/timer_layer.go @@ -728,7 +728,7 @@ func (s *TimerLayerChannelStore) GetAllDirectChannelsForExportAfter(limit int, a return resultVar0, resultVar1 } -func (s *TimerLayerChannelStore) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) { +func (s *TimerLayerChannelStore) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, error) { start := timemodule.Now() resultVar0, resultVar1 := s.ChannelStore.GetByName(team_id, name, allowFromCache) @@ -744,7 +744,7 @@ func (s *TimerLayerChannelStore) GetByName(team_id string, name string, allowFro return resultVar0, resultVar1 } -func (s *TimerLayerChannelStore) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) { +func (s *TimerLayerChannelStore) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, error) { start := timemodule.Now() resultVar0, resultVar1 := s.ChannelStore.GetByNameIncludeDeleted(team_id, name, allowFromCache) @@ -760,7 +760,7 @@ func (s *TimerLayerChannelStore) GetByNameIncludeDeleted(team_id string, name st return resultVar0, resultVar1 } -func (s *TimerLayerChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) { +func (s *TimerLayerChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error) { start := timemodule.Now() resultVar0, resultVar1 := s.ChannelStore.GetByNames(team_id, names, allowFromCache)