diff --git a/model/sharing/invitation.go b/model/sharing/invitation.go index 7e657bdcc3b..97bb2c6a44f 100644 --- a/model/sharing/invitation.go +++ b/model/sharing/invitation.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/url" + "runtime/debug" "time" "github.com/cozy/cozy-stack/model/instance" @@ -38,6 +39,12 @@ func (s *Sharing) SendInvitations(inst *instance.Instance, perms *permission.Per } state := s.Credentials[i-1].State g.Go(func() error { + defer func() { + if r := recover(); r != nil { + inst.Logger().Errorf("[panic] %v: %s", r, debug.Stack()) + } + }() + link := m.InvitationLink(inst, s, state, perms) if m.Instance != "" && canSendShortcut { if err := m.SendShortcut(inst, s, link); err == nil { diff --git a/model/sharing/member.go b/model/sharing/member.go index 0535a0b40fc..2f82153d473 100644 --- a/model/sharing/member.go +++ b/model/sharing/member.go @@ -628,6 +628,10 @@ func (s *Sharing) FindMemberByInboundClientID(clientID string) (*Member, error) // FindCredentials returns the credentials for the given member func (s *Sharing) FindCredentials(m *Member) *Credentials { + if len(s.Credentials) == 0 { + return nil + } + if s.Owner { for i, member := range s.Members { if i > 0 && m.Same(member) { diff --git a/model/sharing/replicator.go b/model/sharing/replicator.go index 798ea56dcf1..d310bd39987 100644 --- a/model/sharing/replicator.go +++ b/model/sharing/replicator.go @@ -8,6 +8,7 @@ import ( "fmt" "net/http" "net/url" + "runtime/debug" "strings" "time" @@ -62,6 +63,11 @@ func (s *Sharing) Replicate(inst *instance.Instance, errors int) error { } m := &s.Members[i] g.Go(func() error { + defer func() { + if r := recover(); r != nil { + inst.Logger().Errorf("[panic] %v: %s", r, debug.Stack()) + } + }() if m.Status == MemberStatusReady { p, err := s.ReplicateTo(inst, m, false) if err != nil { diff --git a/model/sharing/upload.go b/model/sharing/upload.go index 24c54aa5a02..0cc75cf7e16 100644 --- a/model/sharing/upload.go +++ b/model/sharing/upload.go @@ -10,6 +10,7 @@ import ( "net/http" "net/url" "os" + "runtime/debug" "strings" "github.com/cozy/cozy-stack/client/request" @@ -63,6 +64,11 @@ func (s *Sharing) Upload(inst *instance.Instance, ctx context.Context, errors in for i := range members { m := members[i] g.Go(func() error { + defer func() { + if r := recover(); r != nil { + inst.Logger().Errorf("[panic] %v: %s", r, debug.Stack()) + } + }() more, err := s.UploadBatchTo(inst, ctx, m, lastTry) if err != nil { return err