diff --git a/server/platform/services/sharedchannel/service.go b/server/platform/services/sharedchannel/service.go index 7d768c1e72..b1691ab730 100644 --- a/server/platform/services/sharedchannel/service.go +++ b/server/platform/services/sharedchannel/service.go @@ -70,11 +70,6 @@ type errNotFound interface { IsErrNotFound() bool } -// errInvalidInput allows checking against Store.ErrInvalidInput errors without making Store a dependency. -type errInvalidInput interface { - InvalidInputInfo() (entity string, field string, value any) -} - // Service provides shared channel synchronization. type Service struct { server ServerIface diff --git a/server/platform/services/sharedchannel/sync_recv.go b/server/platform/services/sharedchannel/sync_recv.go index a0ae476ae4..0d3dc13332 100644 --- a/server/platform/services/sharedchannel/sync_recv.go +++ b/server/platform/services/sharedchannel/sync_recv.go @@ -248,16 +248,16 @@ func (scs *Service) insertSyncUser(user *model.User, channel *model.Channel, rc user.Email = mungEmail(rc.Name, model.UserEmailMaxLength) if userSaved, err = scs.server.GetStore().User().Save(user); err != nil { - e, ok := err.(errInvalidInput) + field, ok := isConflictError(err) if !ok { break } - _, field, value := e.InvalidInputInfo() if field == "email" || field == "username" { // username or email collision; try again with different suffix scs.server.Log().Log(mlog.LvlSharedChannelServiceWarn, "Collision inserting sync user", mlog.String("field", field), - mlog.Any("value", value), + mlog.String("username", user.Username), + mlog.String("email", user.Email), mlog.Int("attempt", i), mlog.Err(err), ) @@ -302,16 +302,16 @@ func (scs *Service) updateSyncUser(patch *model.UserPatch, user *model.User, cha user.Email = mungEmail(rc.Name, model.UserEmailMaxLength) if update, err = scs.server.GetStore().User().Update(user, false); err != nil { - e, ok := err.(errInvalidInput) + field, ok := isConflictError(err) if !ok { break } - _, field, value := e.InvalidInputInfo() if field == "email" || field == "username" { // username or email collision; try again with different suffix scs.server.Log().Log(mlog.LvlSharedChannelServiceWarn, "Collision updating sync user", mlog.String("field", field), - mlog.Any("value", value), + mlog.String("username", user.Username), + mlog.String("email", user.Email), mlog.Int("attempt", i), mlog.Err(err), ) diff --git a/server/platform/services/sharedchannel/util.go b/server/platform/services/sharedchannel/util.go index 1b106cda3a..a1d8f7ec6d 100644 --- a/server/platform/services/sharedchannel/util.go +++ b/server/platform/services/sharedchannel/util.go @@ -4,10 +4,12 @@ package sharedchannel import ( + "errors" "fmt" "strings" "github.com/mattermost/mattermost/server/public/model" + "github.com/mattermost/mattermost/server/v8/channels/store" ) // fixMention replaces any mentions in a post for the user with the user's real username. @@ -99,3 +101,17 @@ func mungEmail(remotename string, maxLen int) string { } return s } + +func isConflictError(err error) (string, bool) { + var errConflict *store.ErrConflict + if errors.As(err, &errConflict) { + return strings.ToLower(errConflict.Resource), true + } + + var errInput *store.ErrInvalidInput + if errors.As(err, &errInput) { + _, field, _ := errInput.InvalidInputInfo() + return strings.ToLower(field), true + } + return "", false +}