diff --git a/app/channel.go b/app/channel.go index 6a89de154b..8261738c75 100644 --- a/app/channel.go +++ b/app/channel.go @@ -2296,8 +2296,8 @@ func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError { return err } - if err := a.Srv().Store.Channel().PermanentDelete(channel.Id); err != nil { - return err + if nErr := a.Srv().Store.Channel().PermanentDelete(channel.Id); nErr != nil { + return model.NewAppError("PermanentDeleteChannel", "app.channel.permanent_delete.app_error", nil, nErr.Error(), http.StatusInternalServerError) } return nil diff --git a/i18n/en.json b/i18n/en.json index 6e522021db..88b7899101 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -3002,6 +3002,10 @@ "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." }, + { + "id": "app.channel.permanent_delete.app_error", + "translation": "Unable to delete the channel." + }, { "id": "app.channel.post_update_channel_purpose_message.post.error", "translation": "Failed to post channel purpose message" @@ -6246,22 +6250,6 @@ "id": "store.sql_channel.migrate_channel_members.update.app_error", "translation": "Failed to update the channel member." }, - { - "id": "store.sql_channel.permanent_delete.app_error", - "translation": "Unable to delete the channel." - }, - { - "id": "store.sql_channel.permanent_delete.commit_transaction.app_error", - "translation": "Unable to commit transaction." - }, - { - "id": "store.sql_channel.permanent_delete.delete_public_channel.app_error", - "translation": "Unable to delete materialized public channel." - }, - { - "id": "store.sql_channel.permanent_delete.open_transaction.app_error", - "translation": "Unable to open transaction." - }, { "id": "store.sql_channel.permanent_delete_by_team.app_error", "translation": "Unable to delete the channels." diff --git a/store/opentracing_layer.go b/store/opentracing_layer.go index 51526fd6c5..5434d92d4b 100644 --- a/store/opentracing_layer.go +++ b/store/opentracing_layer.go @@ -1503,7 +1503,7 @@ func (s *OpenTracingLayerChannelStore) MigratePublicChannels() error { return resultVar0 } -func (s *OpenTracingLayerChannelStore) PermanentDelete(channelId string) *model.AppError { +func (s *OpenTracingLayerChannelStore) PermanentDelete(channelId string) error { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDelete") s.Root.Store.SetContext(newCtx) diff --git a/store/searchlayer/channel_layer.go b/store/searchlayer/channel_layer.go index 1a1484ffe1..d43ee2f9a2 100644 --- a/store/searchlayer/channel_layer.go +++ b/store/searchlayer/channel_layer.go @@ -194,7 +194,7 @@ func (c *SearchChannelStore) PermanentDeleteMembersByChannel(channelId string) * return err } -func (c *SearchChannelStore) PermanentDelete(channelId string) *model.AppError { +func (c *SearchChannelStore) PermanentDelete(channelId string) error { channel, channelErr := c.ChannelStore.Get(channelId, true) if channelErr != nil { mlog.Error("Encountered error deleting channel", mlog.String("channel_id", channelId), mlog.Err(channelErr)) diff --git a/store/searchtest/helper.go b/store/searchtest/helper.go index 2e08c810d2..c385f70dea 100644 --- a/store/searchtest/helper.go +++ b/store/searchtest/helper.go @@ -317,9 +317,9 @@ func (th *SearchTestHelper) deleteChannel(channel *model.Channel) error { return errors.New(appError.Error()) } - appError = th.Store.Channel().PermanentDelete(channel.Id) - if appError != nil { - return errors.New(appError.Error()) + err := th.Store.Channel().PermanentDelete(channel.Id) + if err != nil { + return err } return nil diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index 5f93fbb6bd..34b6ab5fb0 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -865,15 +865,15 @@ func (s SqlChannelStore) permanentDeleteByTeamtT(transaction *gorp.Transaction, } // PermanentDelete removes the given channel from the database. -func (s SqlChannelStore) PermanentDelete(channelId string) *model.AppError { +func (s SqlChannelStore) PermanentDelete(channelId string) error { transaction, err := s.GetMaster().Begin() if err != nil { - return model.NewAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) + return errors.Wrap(err, "PermanentDelete: begin_transaction") } defer finalizeTransaction(transaction) if err := s.permanentDeleteT(transaction, channelId); err != nil { - return err + return errors.Wrap(err, "permanentDeleteT") } // Additionally propagate the deletion to the PublicChannels table. @@ -885,19 +885,19 @@ func (s SqlChannelStore) PermanentDelete(channelId string) *model.AppError { `, map[string]interface{}{ "ChannelId": channelId, }); err != nil { - return model.NewAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.delete_public_channel.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) + return errors.Wrapf(err, "failed to delete public channels with id=%s", channelId) } if err := transaction.Commit(); err != nil { - return model.NewAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) + return errors.Wrap(err, "PermanentDelete: commit_transaction") } return nil } -func (s SqlChannelStore) permanentDeleteT(transaction *gorp.Transaction, channelId string) *model.AppError { +func (s SqlChannelStore) permanentDeleteT(transaction *gorp.Transaction, channelId string) error { if _, err := transaction.Exec("DELETE FROM Channels WHERE Id = :ChannelId", map[string]interface{}{"ChannelId": channelId}); err != nil { - return model.NewAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) + return errors.Wrapf(err, "failed to delete channel with id=%s", channelId) } return nil diff --git a/store/store.go b/store/store.go index d872bf9690..f080a6dfe8 100644 --- a/store/store.go +++ b/store/store.go @@ -141,7 +141,7 @@ type ChannelStore interface { Delete(channelId string, time int64) error Restore(channelId string, time int64) error SetDeleteAt(channelId string, deleteAt int64, updateAt int64) error - PermanentDelete(channelId string) *model.AppError + PermanentDelete(channelId string) error PermanentDeleteByTeam(teamId string) *model.AppError GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) diff --git a/store/storetest/compliance_store.go b/store/storetest/compliance_store.go index ccc278e96d..a3e457b3e0 100644 --- a/store/storetest/compliance_store.go +++ b/store/storetest/compliance_store.go @@ -31,8 +31,8 @@ func cleanupStoreState(t *testing.T, ss store.Store) { allChannels, err := ss.Channel().GetAllChannels(0, 100000, store.ChannelSearchOpts{IncludeDeleted: true}) require.Nilf(t, err, "error cleaning all test channels: %v", err) for _, channel := range *allChannels { - err = ss.Channel().PermanentDelete(channel.Id) - require.Nil(t, err, "failed cleaning up test channel %s", channel.Id) + nErr := ss.Channel().PermanentDelete(channel.Id) + require.Nil(t, nErr, "failed cleaning up test channel %s", channel.Id) } //remove existing teams diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index 567e53ca4b..740e648219 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -1272,16 +1272,14 @@ func (_m *ChannelStore) MigratePublicChannels() error { } // PermanentDelete provides a mock function with given fields: channelId -func (_m *ChannelStore) PermanentDelete(channelId string) *model.AppError { +func (_m *ChannelStore) PermanentDelete(channelId string) error { ret := _m.Called(channelId) - 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(channelId) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } + r0 = ret.Error(0) } return r0 diff --git a/store/timer_layer.go b/store/timer_layer.go index 924092e3cd..84314e1b66 100644 --- a/store/timer_layer.go +++ b/store/timer_layer.go @@ -1409,7 +1409,7 @@ func (s *TimerLayerChannelStore) MigratePublicChannels() error { return resultVar0 } -func (s *TimerLayerChannelStore) PermanentDelete(channelId string) *model.AppError { +func (s *TimerLayerChannelStore) PermanentDelete(channelId string) error { start := timemodule.Now() resultVar0 := s.ChannelStore.PermanentDelete(channelId)