diff --git a/src/internal/connector/discovery/api/users.go b/src/internal/connector/discovery/api/users.go index 05c1f27f0..ea4b268f6 100644 --- a/src/internal/connector/discovery/api/users.go +++ b/src/internal/connector/discovery/api/users.go @@ -97,7 +97,7 @@ func (c Users) GetAll(ctx context.Context, errs *fault.Bus) ([]models.Userable, resp, err = service.Client().Users().Get(ctx, userOptions(&userFilterNoGuests)) if err != nil { - return nil, clues.Wrap(err, "getting all users").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "getting all users") } iter, err := msgraphgocore.NewPageIterator( @@ -105,7 +105,7 @@ func (c Users) GetAll(ctx context.Context, errs *fault.Bus) ([]models.Userable, service.Adapter(), models.CreateUserCollectionResponseFromDiscriminatorValue) if err != nil { - return nil, clues.Wrap(err, "creating users iterator").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "creating users iterator") } var ( @@ -120,7 +120,7 @@ func (c Users) GetAll(ctx context.Context, errs *fault.Bus) ([]models.Userable, u, err := validateUser(item) if err != nil { - el.AddRecoverable(clues.Wrap(err, "validating user").WithClues(ctx).With(graph.ErrData(err)...)) + el.AddRecoverable(graph.Wrap(ctx, err, "validating user")) } else { us = append(us, u) } @@ -129,7 +129,7 @@ func (c Users) GetAll(ctx context.Context, errs *fault.Bus) ([]models.Userable, } if err := iter.Iterate(ctx, iterator); err != nil { - return nil, clues.Wrap(err, "iterating all users").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "iterating all users") } return us, el.Failure() @@ -144,7 +144,7 @@ func (c Users) GetByID(ctx context.Context, userID string) (models.Userable, err resp, err = c.stable.Client().UsersById(userID).Get(ctx, nil) if err != nil { - return nil, clues.Wrap(err, "getting user").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "getting user") } return resp, err @@ -163,7 +163,7 @@ func (c Users) GetInfo(ctx context.Context, userID string) (*UserInfo, error) { if err != nil { if !graph.IsErrExchangeMailFolderNotFound(err) { - return nil, clues.Wrap(err, "getting user's mail folder").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "getting user's mail folder") } delete(userInfo.DiscoveredServices, path.ExchangeService) diff --git a/src/internal/connector/exchange/api/contacts.go b/src/internal/connector/exchange/api/contacts.go index 7bb237564..79e77e77a 100644 --- a/src/internal/connector/exchange/api/contacts.go +++ b/src/internal/connector/exchange/api/contacts.go @@ -49,7 +49,7 @@ func (c Contacts) CreateContactFolder( mdl, err := c.stable.Client().UsersById(user).ContactFolders().Post(ctx, requestBody, nil) if err != nil { - return nil, clues.Wrap(err, "creating contact folder").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "creating contact folder") } return mdl, nil @@ -62,7 +62,7 @@ func (c Contacts) DeleteContainer( ) error { err := c.stable.Client().UsersById(user).ContactFoldersById(folderID).Delete(ctx, nil) if err != nil { - return clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return graph.Stack(ctx, err) } return nil @@ -76,7 +76,7 @@ func (c Contacts) GetItem( ) (serialization.Parsable, *details.ExchangeInfo, error) { cont, err := c.stable.Client().UsersById(user).ContactsById(itemID).Get(ctx, nil) if err != nil { - return nil, nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, nil, graph.Stack(ctx, err) } return cont, ContactInfo(cont), nil @@ -88,12 +88,12 @@ func (c Contacts) GetContainerByID( ) (graph.Container, error) { ofcf, err := optionsForContactFolderByID([]string{"displayName", "parentFolderId"}) if err != nil { - return nil, clues.Wrap(err, "setting contact folder options").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "setting contact folder options") } resp, err := c.stable.Client().UsersById(userID).ContactFoldersById(dirID).Get(ctx, ofcf) if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } return resp, nil @@ -112,17 +112,14 @@ func (c Contacts) EnumerateContainers( ) error { service, err := c.service() if err != nil { - return clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return graph.Stack(ctx, err) } fields := []string{"displayName", "parentFolderId"} ofcf, err := optionsForContactChildFolders(fields) if err != nil { - return clues.Wrap(err, "setting contact child folder options"). - WithClues(ctx). - With(graph.ErrData(err)...). - With("options_fields", fields) + return graph.Wrap(ctx, err, "setting contact child folder options") } builder := service.Client(). @@ -133,7 +130,7 @@ func (c Contacts) EnumerateContainers( for { resp, err := builder.Get(ctx, ofcf) if err != nil { - return clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return graph.Stack(ctx, err) } for _, fold := range resp.GetValue() { @@ -142,7 +139,7 @@ func (c Contacts) EnumerateContainers( } if err := checkIDAndName(fold); err != nil { - errs.AddRecoverable(clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...)) + errs.AddRecoverable(graph.Stack(ctx, err)) continue } @@ -153,7 +150,7 @@ func (c Contacts) EnumerateContainers( temp := graph.NewCacheFolder(fold, nil, nil) if err := fn(temp); err != nil { - errs.AddRecoverable(clues.Stack(err).WithClues(fctx).With(graph.ErrData(err)...)) + errs.AddRecoverable(graph.Stack(fctx, err)) continue } } @@ -184,7 +181,7 @@ type contactPager struct { func (p *contactPager) getPage(ctx context.Context) (api.DeltaPageLinker, error) { resp, err := p.builder.Get(ctx, p.options) if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } return resp, nil @@ -204,7 +201,7 @@ func (c Contacts) GetAddedAndRemovedItemIDs( ) ([]string, []string, DeltaUpdate, error) { service, err := c.service() if err != nil { - return nil, nil, DeltaUpdate{}, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, nil, DeltaUpdate{}, graph.Stack(ctx, err) } var resetDelta bool @@ -219,7 +216,7 @@ func (c Contacts) GetAddedAndRemovedItemIDs( return nil, nil, DeltaUpdate{}, - clues.Wrap(err, "setting contact folder options").WithClues(ctx).With(graph.ErrData(err)...) + graph.Wrap(ctx, err, "setting contact folder options") } if len(oldDelta) > 0 { @@ -237,7 +234,7 @@ func (c Contacts) GetAddedAndRemovedItemIDs( // only return on error if it is NOT a delta issue. // on bad deltas we retry the call with the regular builder if !graph.IsErrInvalidDelta(err) { - return nil, nil, DeltaUpdate{}, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, nil, DeltaUpdate{}, graph.Stack(ctx, err) } resetDelta = true @@ -293,12 +290,12 @@ func (c Contacts) Serialize( defer writer.Close() if err = writer.WriteObjectValue("", contact); err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } bs, err := writer.GetSerializedContent() if err != nil { - return nil, clues.Wrap(err, "serializing contact").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "serializing contact") } return bs, nil diff --git a/src/internal/connector/exchange/api/events.go b/src/internal/connector/exchange/api/events.go index 845594b78..f63efeaaf 100644 --- a/src/internal/connector/exchange/api/events.go +++ b/src/internal/connector/exchange/api/events.go @@ -50,7 +50,7 @@ func (c Events) CreateCalendar( mdl, err := c.stable.Client().UsersById(user).Calendars().Post(ctx, requestbody, nil) if err != nil { - return nil, clues.Wrap(err, "creating calendar").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "creating calendar") } return mdl, nil @@ -64,7 +64,7 @@ func (c Events) DeleteContainer( ) error { err := c.stable.Client().UsersById(user).CalendarsById(calendarID).Delete(ctx, nil) if err != nil { - return clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return graph.Stack(ctx, err) } return nil @@ -76,17 +76,17 @@ func (c Events) GetContainerByID( ) (graph.Container, error) { service, err := c.service() if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } ofc, err := optionsForCalendarsByID([]string{"name", "owner"}) if err != nil { - return nil, clues.Wrap(err, "setting event calendar options").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "setting event calendar options") } cal, err := service.Client().UsersById(userID).CalendarsById(containerID).Get(ctx, ofc) if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err).WithClues(ctx) } return graph.CalendarDisplayable{Calendarable: cal}, nil @@ -105,7 +105,7 @@ func (c Events) GetItem( event, err = c.stable.Client().UsersById(user).EventsById(itemID).Get(ctx, nil) if err != nil { - return nil, nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, nil, graph.Stack(ctx, err) } if *event.GetHasAttachments() || HasAttachments(event.GetBody()) { @@ -122,7 +122,7 @@ func (c Events) GetItem( Attachments(). Get(ctx, options) if err != nil { - return nil, nil, clues.Wrap(err, "event attachment download").WithClues(ctx).With(graph.ErrData(err)...) + return nil, nil, graph.Wrap(ctx, err, "event attachment download") } event.SetAttachments(attached.GetValue()) @@ -144,12 +144,12 @@ func (c Events) EnumerateContainers( ) error { service, err := c.service() if err != nil { - return clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return graph.Stack(ctx, err) } ofc, err := optionsForCalendars([]string{"name"}) if err != nil { - return clues.Wrap(err, "setting calendar options").WithClues(ctx).With(graph.ErrData(err)...) + return graph.Wrap(ctx, err, "setting calendar options") } builder := service.Client().UsersById(userID).Calendars() @@ -157,13 +157,13 @@ func (c Events) EnumerateContainers( for { resp, err := builder.Get(ctx, ofc) if err != nil { - return clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return graph.Stack(ctx, err) } for _, cal := range resp.GetValue() { cd := CalendarDisplayable{Calendarable: cal} if err := checkIDAndName(cd); err != nil { - errs.AddRecoverable(clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...)) + errs.AddRecoverable(graph.Stack(ctx, err)) continue } @@ -177,7 +177,7 @@ func (c Events) EnumerateContainers( path.Builder{}.Append(ptr.Val(cd.GetId())), // storage path path.Builder{}.Append(ptr.Val(cd.GetDisplayName()))) // display location if err := fn(temp); err != nil { - errs.AddRecoverable(clues.Stack(err).WithClues(fctx).With(graph.ErrData(err)...)) + errs.AddRecoverable(graph.Stack(fctx, err)) continue } } @@ -212,7 +212,7 @@ type eventPager struct { func (p *eventPager) getPage(ctx context.Context) (api.DeltaPageLinker, error) { resp, err := p.builder.Get(ctx, p.options) if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } return resp, nil @@ -255,7 +255,7 @@ func (c Events) GetAddedAndRemovedItemIDs( // only return on error if it is NOT a delta issue. // on bad deltas we retry the call with the regular builder if !graph.IsErrInvalidDelta(err) { - return nil, nil, DeltaUpdate{}, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, nil, DeltaUpdate{}, graph.Stack(ctx, err) } resetDelta = true @@ -321,12 +321,12 @@ func (c Events) Serialize( defer writer.Close() if err = writer.WriteObjectValue("", event); err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } bs, err := writer.GetSerializedContent() if err != nil { - return nil, clues.Wrap(err, "serializing event").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "serializing event") } return bs, nil diff --git a/src/internal/connector/exchange/api/mail.go b/src/internal/connector/exchange/api/mail.go index 9effd1011..918ad4621 100644 --- a/src/internal/connector/exchange/api/mail.go +++ b/src/internal/connector/exchange/api/mail.go @@ -50,7 +50,7 @@ func (c Mail) CreateMailFolder( mdl, err := c.stable.Client().UsersById(user).MailFolders().Post(ctx, requestBody, nil) if err != nil { - return nil, clues.Wrap(err, "creating mail folder").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "creating mail folder") } return mdl, nil @@ -62,7 +62,7 @@ func (c Mail) CreateMailFolderWithParent( ) (models.MailFolderable, error) { service, err := c.service() if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } isHidden := false @@ -77,7 +77,7 @@ func (c Mail) CreateMailFolderWithParent( ChildFolders(). Post(ctx, requestBody, nil) if err != nil { - return nil, clues.Wrap(err, "creating nested mail folder").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "creating nested mail folder") } return mdl, nil @@ -91,7 +91,7 @@ func (c Mail) DeleteContainer( ) error { err := c.stable.Client().UsersById(user).MailFoldersById(folderID).Delete(ctx, nil) if err != nil { - return clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return graph.Stack(ctx, err) } return nil @@ -103,17 +103,17 @@ func (c Mail) GetContainerByID( ) (graph.Container, error) { service, err := c.service() if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } ofmf, err := optionsForMailFoldersItem([]string{"displayName", "parentFolderId"}) if err != nil { - return nil, clues.Wrap(err, "setting mail folder options").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "setting mail folder options") } resp, err := service.Client().UsersById(userID).MailFoldersById(dirID).Get(ctx, ofmf) if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } return resp, nil @@ -128,7 +128,7 @@ func (c Mail) GetItem( ) (serialization.Parsable, *details.ExchangeInfo, error) { mail, err := c.stable.Client().UsersById(user).MessagesById(itemID).Get(ctx, nil) if err != nil { - return nil, nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, nil, graph.Stack(ctx, err) } if *mail.GetHasAttachments() || HasAttachments(mail.GetBody()) { @@ -145,7 +145,7 @@ func (c Mail) GetItem( Attachments(). Get(ctx, options) if err != nil { - return nil, nil, clues.Wrap(err, "mail attachment download").WithClues(ctx).With(graph.ErrData(err)...) + return nil, nil, graph.Wrap(ctx, err, "mail attachment download") } mail.SetAttachments(attached.GetValue()) @@ -167,7 +167,7 @@ func (c Mail) EnumerateContainers( ) error { service, err := c.service() if err != nil { - return clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return graph.Stack(ctx, err) } builder := service.Client(). @@ -178,7 +178,7 @@ func (c Mail) EnumerateContainers( for { resp, err := builder.Get(ctx, nil) if err != nil { - return clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return graph.Stack(ctx, err) } for _, v := range resp.GetValue() { @@ -189,7 +189,7 @@ func (c Mail) EnumerateContainers( temp := graph.NewCacheFolder(v, nil, nil) if err := fn(temp); err != nil { - errs.AddRecoverable(clues.Stack(err).WithClues(fctx).With(graph.ErrData(err)...)) + errs.AddRecoverable(graph.Stack(fctx, err)) continue } } @@ -220,7 +220,7 @@ type mailPager struct { func (p *mailPager) getPage(ctx context.Context) (api.DeltaPageLinker, error) { page, err := p.builder.Get(ctx, p.options) if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } return page, nil @@ -258,7 +258,7 @@ func (c Mail) GetAddedAndRemovedItemIDs( return nil, nil, DeltaUpdate{}, - clues.Wrap(err, "setting contact folder options").WithClues(ctx).With(graph.ErrData(err)...) + graph.Wrap(ctx, err, "setting contact folder options") } if len(oldDelta) > 0 { @@ -331,12 +331,12 @@ func (c Mail) Serialize( defer writer.Close() if err = writer.WriteObjectValue("", msg); err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } bs, err := writer.GetSerializedContent() if err != nil { - return nil, clues.Wrap(err, "serializing email").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "serializing email") } return bs, nil diff --git a/src/internal/connector/exchange/api/shared.go b/src/internal/connector/exchange/api/shared.go index b5f9a7466..8431f58c5 100644 --- a/src/internal/connector/exchange/api/shared.go +++ b/src/internal/connector/exchange/api/shared.go @@ -74,14 +74,14 @@ func getItemsAddedAndRemovedFromContainer( // get the next page of data, check for standard errors resp, err := pager.getPage(ctx) if err != nil { - return nil, nil, deltaURL, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, nil, deltaURL, graph.Stack(ctx, err) } // each category type responds with a different interface, but all // of them comply with GetValue, which is where we'll get our item data. items, err := pager.valuesIn(resp) if err != nil { - return nil, nil, "", clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, nil, "", graph.Stack(ctx, err) } itemCount += len(items) diff --git a/src/internal/connector/exchange/attachment_uploadable.go b/src/internal/connector/exchange/attachment_uploadable.go index cd7d2710d..fa03fa214 100644 --- a/src/internal/connector/exchange/attachment_uploadable.go +++ b/src/internal/connector/exchange/attachment_uploadable.go @@ -3,7 +3,6 @@ package exchange import ( "context" - "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" msusers "github.com/microsoftgraph/msgraph-sdk-go/users" @@ -44,7 +43,7 @@ func (mau *mailAttachmentUploader) uploadSmallAttachment(ctx context.Context, at Attachments(). Post(ctx, attach, nil) if err != nil { - return clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return graph.Stack(ctx, err) } return nil @@ -68,7 +67,7 @@ func (mau *mailAttachmentUploader) uploadSession( CreateUploadSession(). Post(ctx, session, nil) if err != nil { - return nil, clues.Wrap(err, "uploading mail attachment").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "uploading mail attachment") } return r, nil @@ -94,7 +93,7 @@ func (eau *eventAttachmentUploader) uploadSmallAttachment(ctx context.Context, a Attachments(). Post(ctx, attach, nil) if err != nil { - return clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return graph.Stack(ctx, err) } return nil @@ -116,7 +115,7 @@ func (eau *eventAttachmentUploader) uploadSession( CreateUploadSession(). Post(ctx, session, nil) if err != nil { - return nil, clues.Wrap(err, "uploading event attachment").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "uploading event attachment") } return r, nil diff --git a/src/internal/connector/exchange/service_restore.go b/src/internal/connector/exchange/service_restore.go index 1f5c70347..294be3ec6 100644 --- a/src/internal/connector/exchange/service_restore.go +++ b/src/internal/connector/exchange/service_restore.go @@ -70,14 +70,14 @@ func RestoreExchangeContact( ) (*details.ExchangeInfo, error) { contact, err := support.CreateContactFromBytes(bits) if err != nil { - return nil, clues.Wrap(err, "creating contact from bytes").WithClues(ctx) + return nil, graph.Wrap(ctx, err, "creating contact from bytes") } ctx = clues.Add(ctx, "item_id", ptr.Val(contact.GetId())) response, err := service.Client().UsersById(user).ContactFoldersById(destination).Contacts().Post(ctx, contact, nil) if err != nil { - return nil, clues.Wrap(err, "uploading Contact").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "uploading Contact") } if response == nil { @@ -125,7 +125,7 @@ func RestoreExchangeEvent( response, err := service.Client().UsersById(user).CalendarsById(destination).Events().Post(ctx, transformedEvent, nil) if err != nil { - return nil, clues.Wrap(err, "uploading event").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "uploading event") } if response == nil { @@ -249,7 +249,7 @@ func SendMailToBackStore( response, err := service.Client().UsersById(user).MailFoldersById(destination).Messages().Post(ctx, message, nil) if err != nil { - return clues.Wrap(err, "restoring mail").WithClues(ctx).With(graph.ErrData(err)...) + return graph.Wrap(ctx, err, "restoring mail") } if response == nil { diff --git a/src/internal/connector/graph/errors.go b/src/internal/connector/graph/errors.go index b8399da4c..e0d93db1d 100644 --- a/src/internal/connector/graph/errors.go +++ b/src/internal/connector/graph/errors.go @@ -6,12 +6,15 @@ import ( "net/http" "net/url" "os" + "strings" "github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors" "github.com/pkg/errors" "golang.org/x/exp/slices" + "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" + "github.com/alcionai/corso/src/internal/common/ptr" ) // --------------------------------------------------------------------------- @@ -40,6 +43,17 @@ var ( Err500InternalServerError = errors.New("500 Internal Server Error") ) +var ( + mysiteURLNotFound = "unable to retrieve user's mysite URL" + mysiteNotFound = "user's mysite not found" +) + +var Labels = struct { + MysiteNotFound string +}{ + MysiteNotFound: "mysite_not_found", +} + // The folder or item was deleted between the time we identified // it and when we tried to fetch data for it. type ErrDeletedInFlight struct { @@ -179,43 +193,74 @@ func hasErrorCode(err error, codes ...string) bool { return slices.Contains(codes, *oDataError.GetError().GetCode()) } -// ErrData is a helper function that extracts ODataError metadata from -// the error. If the error is not an ODataError type, returns an empty -// slice. The returned value is guaranteed to be an even-length pairing -// of key, value tuples. -func ErrData(e error) []any { - result := make([]any, 0) - +// Wrap is a helper function that extracts ODataError metadata from +// the error. If the error is not an ODataError type, returns the error. +func Wrap(ctx context.Context, e error, msg string) *clues.Err { if e == nil { - return result + return nil } odErr, ok := e.(odataerrors.ODataErrorable) if !ok { - return result + return clues.Wrap(e, msg).WithClues(ctx) } - // Get MainError - mainErr := odErr.GetError() + data, innerMsg := ErrData(odErr) - result = appendIf(result, "odataerror_code", mainErr.GetCode()) - result = appendIf(result, "odataerror_message", mainErr.GetMessage()) - result = appendIf(result, "odataerror_target", mainErr.GetTarget()) + return setLabels(clues.Wrap(e, msg).WithClues(ctx).With(data...), innerMsg) +} + +// Stack is a helper function that extracts ODataError metadata from +// the error. If the error is not an ODataError type, returns the error. +func Stack(ctx context.Context, e error) *clues.Err { + if e == nil { + return nil + } + + odErr, ok := e.(odataerrors.ODataErrorable) + if !ok { + return clues.Stack(e).WithClues(ctx) + } + + data, innerMsg := ErrData(odErr) + + return setLabels(clues.Stack(e).WithClues(ctx).With(data...), innerMsg) +} + +func setLabels(err *clues.Err, msg string) *clues.Err { + if strings.Contains(msg, mysiteNotFound) || strings.Contains(msg, mysiteURLNotFound) { + err = err.Label(Labels.MysiteNotFound) + } + + return err +} + +func ErrData(err odataerrors.ODataErrorable) ([]any, string) { + data := make([]any, 0) + + // Get MainError + mainErr := err.GetError() + + data = appendIf(data, "odataerror_code", mainErr.GetCode()) + data = appendIf(data, "odataerror_message", mainErr.GetMessage()) + data = appendIf(data, "odataerror_target", mainErr.GetTarget()) + msgConcat := ptr.Val(mainErr.GetMessage()) for i, d := range mainErr.GetDetails() { pfx := fmt.Sprintf("odataerror_details_%d_", i) - result = appendIf(result, pfx+"code", d.GetCode()) - result = appendIf(result, pfx+"message", d.GetMessage()) - result = appendIf(result, pfx+"target", d.GetTarget()) + data = appendIf(data, pfx+"code", d.GetCode()) + data = appendIf(data, pfx+"message", d.GetMessage()) + data = appendIf(data, pfx+"target", d.GetTarget()) + msgConcat += ptr.Val(d.GetMessage()) } inner := mainErr.GetInnererror() if inner != nil { - result = appendIf(result, "odataerror_inner_cli_req_id", inner.GetClientRequestId()) - result = appendIf(result, "odataerror_inner_req_id", inner.GetRequestId()) + data = appendIf(data, "odataerror_inner_cli_req_id", inner.GetClientRequestId()) + data = appendIf(data, "odataerror_inner_req_id", inner.GetRequestId()) } - return result + return data, strings.ToLower(msgConcat) } func appendIf(a []any, k string, v *string) []any { diff --git a/src/internal/connector/graph/retry_middleware.go b/src/internal/connector/graph/retry_middleware.go index 371502a59..c836a251b 100644 --- a/src/internal/connector/graph/retry_middleware.go +++ b/src/internal/connector/graph/retry_middleware.go @@ -6,7 +6,6 @@ import ( "strconv" "time" - "github.com/alcionai/clues" backoff "github.com/cenkalti/backoff/v4" khttp "github.com/microsoft/kiota-http-go" ) @@ -50,10 +49,7 @@ func (middleware RetryHandler) retryRequest( response, err := pipeline.Next(req, middlewareIndex) if err != nil && !IsErrTimeout(err) { - return response, clues.Stack(err). - WithClues(ctx). - With("retry_count", executionCount). - With(ErrData(err)...) + return response, Stack(ctx, err).With("retry_count", executionCount) } return middleware.retryRequest(ctx, @@ -68,10 +64,7 @@ func (middleware RetryHandler) retryRequest( } if respErr != nil { - return nil, clues.Stack(respErr). - WithClues(ctx). - With("retry_count", executionCount). - With(ErrData(respErr)...) + return nil, Stack(ctx, respErr).With("retry_count", executionCount) } return resp, nil diff --git a/src/internal/connector/graph/service.go b/src/internal/connector/graph/service.go index 275e76378..c62fc1b78 100644 --- a/src/internal/connector/graph/service.go +++ b/src/internal/connector/graph/service.go @@ -8,7 +8,6 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/alcionai/clues" backoff "github.com/cenkalti/backoff/v4" "github.com/microsoft/kiota-abstractions-go/serialization" ka "github.com/microsoft/kiota-authentication-azure-go" @@ -336,7 +335,7 @@ func (middleware RetryHandler) Intercept( response, err := pipeline.Next(req, middlewareIndex) if err != nil && !IsErrTimeout(err) { - return response, clues.Stack(err).WithClues(ctx).With(ErrData(err)...) + return response, Stack(ctx, err) } exponentialBackOff := backoff.NewExponentialBackOff() @@ -354,7 +353,7 @@ func (middleware RetryHandler) Intercept( exponentialBackOff, err) if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(ErrData(err)...) + return nil, Stack(ctx, err) } return response, nil diff --git a/src/internal/connector/graph_connector.go b/src/internal/connector/graph_connector.go index 13e89e93e..dd01e7e0f 100644 --- a/src/internal/connector/graph_connector.go +++ b/src/internal/connector/graph_connector.go @@ -320,14 +320,12 @@ func getResources( response, err := query(ctx, gs) if err != nil { - return nil, clues.Wrap(err, "retrieving tenant's resources"). - WithClues(ctx). - With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "retrieving tenant's resources") } iter, err := msgraphgocore.NewPageIterator(response, gs.Adapter(), parser) if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } el := errs.Local() @@ -354,7 +352,7 @@ func getResources( } if err := iter.Iterate(ctx, callbackFunc); err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } return resources, el.Failure() diff --git a/src/internal/connector/graph_connector_test.go b/src/internal/connector/graph_connector_test.go index 8d0d88bd2..9293d8c74 100644 --- a/src/internal/connector/graph_connector_test.go +++ b/src/internal/connector/graph_connector_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/suite" "golang.org/x/exp/maps" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/discovery/api" "github.com/alcionai/corso/src/internal/connector/graph" @@ -349,7 +348,7 @@ func mustGetDefaultDriveID( //revive:enable:context-as-argument d, err := service.Client().UsersById(userID).Drive().Get(ctx, nil) if err != nil { - err = clues.Wrap(err, "retrieving drive").WithClues(ctx).With(graph.ErrData(err)...) + err = graph.Wrap(ctx, err, "retrieving drive") } require.NoError(t, err) diff --git a/src/internal/connector/onedrive/api/drive.go b/src/internal/connector/onedrive/api/drive.go index 8f9471cef..7f39899b9 100644 --- a/src/internal/connector/onedrive/api/drive.go +++ b/src/internal/connector/onedrive/api/drive.go @@ -68,7 +68,7 @@ func (p *driveItemPager) GetPage(ctx context.Context) (api.DeltaPageLinker, erro resp, err = p.builder.Get(ctx, p.options) if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } return resp, nil @@ -165,7 +165,7 @@ func (p *siteDrivePager) GetPage(ctx context.Context) (api.PageLinker, error) { resp, err = p.builder.Get(ctx, p.options) if err != nil { - return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, err) } return resp, nil diff --git a/src/internal/connector/onedrive/collection.go b/src/internal/connector/onedrive/collection.go index d01cb00fd..038849654 100644 --- a/src/internal/connector/onedrive/collection.go +++ b/src/internal/connector/onedrive/collection.go @@ -82,6 +82,7 @@ type Collection struct { // itemReadFunc returns a reader for the specified item type itemReaderFunc func( + ctx context.Context, hc *http.Client, item models.DriveItemable, ) (details.ItemInfo, io.ReadCloser, error) @@ -334,7 +335,7 @@ func (oc *Collection) populateItems(ctx context.Context, errs *fault.Bus) { err error ) - _, itemData, err = oc.itemReader(oc.itemClient, item) + _, itemData, err = oc.itemReader(ctx, oc.itemClient, item) if err != nil && graph.IsErrUnauthorized(err) { // assume unauthorized requests are a sign of an expired diff --git a/src/internal/connector/onedrive/collection_test.go b/src/internal/connector/onedrive/collection_test.go index 18da1351f..fb7a40338 100644 --- a/src/internal/connector/onedrive/collection_test.go +++ b/src/internal/connector/onedrive/collection_test.go @@ -94,7 +94,7 @@ func (suite *CollectionUnitTestSuite) TestCollection() { numInstances: 1, source: OneDriveSource, itemDeets: nst{testItemName, 42, now}, - itemReader: func(*http.Client, models.DriveItemable) (details.ItemInfo, io.ReadCloser, error) { + itemReader: func(context.Context, *http.Client, models.DriveItemable) (details.ItemInfo, io.ReadCloser, error) { return details.ItemInfo{OneDrive: &details.OneDriveInfo{ItemName: testItemName, Modified: now}}, io.NopCloser(bytes.NewReader(testItemData)), nil @@ -109,7 +109,7 @@ func (suite *CollectionUnitTestSuite) TestCollection() { numInstances: 3, source: OneDriveSource, itemDeets: nst{testItemName, 42, now}, - itemReader: func(*http.Client, models.DriveItemable) (details.ItemInfo, io.ReadCloser, error) { + itemReader: func(context.Context, *http.Client, models.DriveItemable) (details.ItemInfo, io.ReadCloser, error) { return details.ItemInfo{OneDrive: &details.OneDriveInfo{ItemName: testItemName, Modified: now}}, io.NopCloser(bytes.NewReader(testItemData)), nil @@ -124,7 +124,7 @@ func (suite *CollectionUnitTestSuite) TestCollection() { numInstances: 1, source: SharePointSource, itemDeets: nst{testItemName, 42, now}, - itemReader: func(*http.Client, models.DriveItemable) (details.ItemInfo, io.ReadCloser, error) { + itemReader: func(context.Context, *http.Client, models.DriveItemable) (details.ItemInfo, io.ReadCloser, error) { return details.ItemInfo{SharePoint: &details.SharePointInfo{ItemName: testItemName, Modified: now}}, io.NopCloser(bytes.NewReader(testItemData)), nil @@ -139,7 +139,7 @@ func (suite *CollectionUnitTestSuite) TestCollection() { numInstances: 3, source: SharePointSource, itemDeets: nst{testItemName, 42, now}, - itemReader: func(*http.Client, models.DriveItemable) (details.ItemInfo, io.ReadCloser, error) { + itemReader: func(context.Context, *http.Client, models.DriveItemable) (details.ItemInfo, io.ReadCloser, error) { return details.ItemInfo{SharePoint: &details.SharePointInfo{ItemName: testItemName, Modified: now}}, io.NopCloser(bytes.NewReader(testItemData)), nil @@ -323,7 +323,11 @@ func (suite *CollectionUnitTestSuite) TestCollectionReadError() { mockItem.SetLastModifiedDateTime(&now) coll.Add(mockItem) - coll.itemReader = func(*http.Client, models.DriveItemable) (details.ItemInfo, io.ReadCloser, error) { + coll.itemReader = func( + context.Context, + *http.Client, + models.DriveItemable, + ) (details.ItemInfo, io.ReadCloser, error) { return details.ItemInfo{}, nil, assert.AnError } @@ -400,6 +404,7 @@ func (suite *CollectionUnitTestSuite) TestCollectionDisablePermissionsBackup() { coll.Add(mockItem) coll.itemReader = func( + context.Context, *http.Client, models.DriveItemable, ) (details.ItemInfo, io.ReadCloser, error) { @@ -490,6 +495,7 @@ func (suite *CollectionUnitTestSuite) TestCollectionPermissionBackupLatestModTim coll.Add(mockItem) coll.itemReader = func( + context.Context, *http.Client, models.DriveItemable, ) (details.ItemInfo, io.ReadCloser, error) { diff --git a/src/internal/connector/onedrive/collections.go b/src/internal/connector/onedrive/collections.go index 687cfebf0..732b60296 100644 --- a/src/internal/connector/onedrive/collections.go +++ b/src/internal/connector/onedrive/collections.go @@ -268,7 +268,7 @@ func (c *Collections) Get( // Enumerate drives for the specified resourceOwner pager, err := c.drivePagerFunc(c.source, c.service, c.resourceOwner, nil) if err != nil { - return nil, nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, nil, graph.Stack(ctx, err) } retry := c.source == OneDriveSource diff --git a/src/internal/connector/onedrive/drive.go b/src/internal/connector/onedrive/drive.go index 8cb75cb35..8b35b34cd 100644 --- a/src/internal/connector/onedrive/drive.go +++ b/src/internal/connector/onedrive/drive.go @@ -27,15 +27,13 @@ const ( // nextLinkKey is used to find the next link in a paged // graph response - nextLinkKey = "@odata.nextLink" - itemChildrenRawURLFmt = "https://graph.microsoft.com/v1.0/drives/%s/items/%s/children" - itemByPathRawURLFmt = "https://graph.microsoft.com/v1.0/drives/%s/items/%s:/%s" - itemNotFoundErrorCode = "itemNotFound" - userMysiteURLNotFound = "BadRequest Unable to retrieve user's mysite URL" - userMysiteURLNotFoundMsg = "Unable to retrieve user's mysite URL" - userMysiteNotFound = "ResourceNotFound User's mysite not found" - userMysiteNotFoundMsg = "User's mysite not found" - contextDeadlineExceeded = "context deadline exceeded" + nextLinkKey = "@odata.nextLink" + itemChildrenRawURLFmt = "https://graph.microsoft.com/v1.0/drives/%s/items/%s/children" + itemByPathRawURLFmt = "https://graph.microsoft.com/v1.0/drives/%s/items/%s:/%s" + itemNotFoundErrorCode = "itemNotFound" + userMysiteURLNotFound = "BadRequest Unable to retrieve user's mysite URL" + userMysiteNotFound = "ResourceNotFound User's mysite not found" + contextDeadlineExceeded = "context deadline exceeded" ) // DeltaUpdate holds the results of a current delta token. It normally @@ -96,24 +94,17 @@ func drives( for i := 0; i <= numberOfRetries; i++ { page, err = pager.GetPage(ctx) if err != nil { - // Various error handling. May return an error or perform a retry. - // errMsg := support.ConnectorStackErrorTraceWrap(err, "").Error() - // temporarily broken until ^ is fixed in next PR. - errMsg := err.Error() - if strings.Contains(errMsg, userMysiteURLNotFound) || - strings.Contains(errMsg, userMysiteURLNotFoundMsg) || - strings.Contains(errMsg, userMysiteNotFound) || - strings.Contains(errMsg, userMysiteNotFoundMsg) { + if clues.HasLabel(err, graph.Labels.MysiteNotFound) { logger.Ctx(ctx).Infof("resource owner does not have a drive") return make([]models.Driveable, 0), nil // no license or drives. } - if strings.Contains(errMsg, contextDeadlineExceeded) && i < numberOfRetries { + if errors.Is(err, context.DeadlineExceeded) && i < numberOfRetries { time.Sleep(time.Duration(3*(i+1)) * time.Second) continue } - return nil, clues.Wrap(err, "retrieving drives").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "retrieving drives") } // No error encountered, break the retry loop so we can extract results @@ -123,7 +114,7 @@ func drives( tmp, err := pager.ValuesIn(page) if err != nil { - return nil, clues.Wrap(err, "extracting drives from response").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "extracting drives from response") } drives = append(drives, tmp...) @@ -223,14 +214,12 @@ func collectItems( } if err != nil { - return DeltaUpdate{}, nil, nil, clues.Wrap(err, "getting page").WithClues(ctx).With(graph.ErrData(err)...) + return DeltaUpdate{}, nil, nil, graph.Wrap(ctx, err, "getting page") } vals, err := pager.ValuesIn(page) if err != nil { - return DeltaUpdate{}, nil, nil, clues.Wrap(err, "extracting items from response"). - WithClues(ctx). - With(graph.ErrData(err)...) + return DeltaUpdate{}, nil, nil, graph.Wrap(ctx, err, "extracting items from response") } err = collector(ctx, driveID, driveName, vals, oldPaths, newPaths, excluded, invalidPrevDelta, errs) @@ -279,15 +268,15 @@ func getFolder( if err != nil { if graph.IsErrDeletedInFlight(err) { - return nil, clues.Stack(errFolderNotFound, err).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, clues.Stack(errFolderNotFound, err)) } - return nil, clues.Wrap(err, "getting folder").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "getting folder") } // Check if the item found is a folder, fail the call if not if foundItem.GetFolder() == nil { - return nil, clues.Stack(errFolderNotFound).WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Stack(ctx, errFolderNotFound) } return foundItem, nil @@ -307,7 +296,7 @@ func createItem( newItem, err := builder.Post(ctx, newItem, nil) if err != nil { - return nil, clues.Wrap(err, "creating item").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "creating item") } return newItem, nil @@ -428,10 +417,7 @@ func DeleteItem( ) error { err := gs.Client().DrivesById(driveID).ItemsById(itemID).Delete(ctx, nil) if err != nil { - return clues.Wrap(err, "deleting item"). - WithClues(ctx). - With("item_id", itemID). - With(graph.ErrData(err)...) + return graph.Wrap(ctx, err, "deleting item").With("item_id", itemID) } return nil diff --git a/src/internal/connector/onedrive/item.go b/src/internal/connector/onedrive/item.go index 1a1418c7d..bc7890a45 100644 --- a/src/internal/connector/onedrive/item.go +++ b/src/internal/connector/onedrive/item.go @@ -35,7 +35,7 @@ func getDriveItem( ) (models.DriveItemable, error) { di, err := srv.Client().DrivesById(driveID).ItemsById(itemID).Get(ctx, nil) if err != nil { - return nil, clues.Wrap(err, "getting item").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "getting item") } return di, nil @@ -46,10 +46,11 @@ func getDriveItem( // and using a http client to initialize a reader // TODO: Add metadata fetching to SharePoint func sharePointItemReader( + ctx context.Context, hc *http.Client, item models.DriveItemable, ) (details.ItemInfo, io.ReadCloser, error) { - resp, err := downloadItem(hc, item) + resp, err := downloadItem(ctx, hc, item) if err != nil { return details.ItemInfo{}, nil, errors.Wrap(err, "downloading item") } @@ -84,6 +85,7 @@ func oneDriveItemMetaReader( // It crafts this by querying M365 for a download URL for the item // and using a http client to initialize a reader func oneDriveItemReader( + ctx context.Context, hc *http.Client, item models.DriveItemable, ) (details.ItemInfo, io.ReadCloser, error) { @@ -93,7 +95,7 @@ func oneDriveItemReader( ) if isFile { - resp, err := downloadItem(hc, item) + resp, err := downloadItem(ctx, hc, item) if err != nil { return details.ItemInfo{}, nil, errors.Wrap(err, "downloading item") } @@ -108,7 +110,7 @@ func oneDriveItemReader( return dii, rc, nil } -func downloadItem(hc *http.Client, item models.DriveItemable) (*http.Response, error) { +func downloadItem(ctx context.Context, hc *http.Client, item models.DriveItemable) (*http.Response, error) { url, ok := item.GetAdditionalData()[downloadURLKey].(*string) if !ok { return nil, clues.New("extracting file url").With("item_id", ptr.Val(item.GetId())) @@ -116,7 +118,7 @@ func downloadItem(hc *http.Client, item models.DriveItemable) (*http.Response, e req, err := http.NewRequest(http.MethodGet, *url, nil) if err != nil { - return nil, clues.Wrap(err, "new request").With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "new request") } //nolint:lll @@ -198,7 +200,7 @@ func oneDriveItemMetaInfo( Permissions(). Get(ctx, nil) if err != nil { - return Metadata{}, clues.Wrap(err, "getting item metadata").WithClues(ctx).With(graph.ErrData(err)...) + return Metadata{}, graph.Wrap(ctx, err, "getting item metadata") } uperms := filterUserPermissions(perm.GetValue()) @@ -306,9 +308,7 @@ func driveItemWriter( r, err := service.Client().DrivesById(driveID).ItemsById(itemID).CreateUploadSession().Post(ctx, session, nil) if err != nil { - return nil, clues.Wrap(err, "creating item upload session"). - WithClues(ctx). - With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "creating item upload session") } logger.Ctx(ctx).Debug("created an upload session") diff --git a/src/internal/connector/onedrive/item_test.go b/src/internal/connector/onedrive/item_test.go index 5b3f5b5bc..9d461a6a5 100644 --- a/src/internal/connector/onedrive/item_test.go +++ b/src/internal/connector/onedrive/item_test.go @@ -144,7 +144,7 @@ func (suite *ItemIntegrationSuite) TestItemReader_oneDrive() { ) // Read data for the file - itemInfo, itemData, err := oneDriveItemReader(graph.HTTPClient(graph.NoTimeout()), driveItem) + itemInfo, itemData, err := oneDriveItemReader(ctx, graph.HTTPClient(graph.NoTimeout()), driveItem) require.NoError(suite.T(), err) require.NotNil(suite.T(), itemInfo.OneDrive) diff --git a/src/internal/connector/onedrive/restore.go b/src/internal/connector/onedrive/restore.go index 81f2ce8fb..07505095e 100644 --- a/src/internal/connector/onedrive/restore.go +++ b/src/internal/connector/onedrive/restore.go @@ -449,7 +449,7 @@ func CreateRestoreFolders( ) (string, error) { driveRoot, err := service.Client().DrivesById(driveID).Root().Get(ctx, nil) if err != nil { - return "", clues.Wrap(err, "getting drive root").WithClues(ctx).With(graph.ErrData(err)...) + return "", graph.Wrap(ctx, err, "getting drive root") } parentFolderID := ptr.Val(driveRoot.GetId()) @@ -525,7 +525,7 @@ func restoreData( // Upload the stream data written, err := io.CopyBuffer(w, progReader, copyBuffer) if err != nil { - return "", details.ItemInfo{}, clues.Wrap(err, "writing item bytes").WithClues(ctx).With(graph.ErrData(err)...) + return "", details.ItemInfo{}, graph.Wrap(ctx, err, "writing item bytes") } dii := details.ItemInfo{} @@ -625,7 +625,7 @@ func restorePermissions( PermissionsById(permissionIDMappings[p.ID]). Delete(ctx, nil) if err != nil { - return permissionIDMappings, clues.Wrap(err, "removing permissions").WithClues(ctx).With(graph.ErrData(err)...) + return permissionIDMappings, graph.Wrap(ctx, err, "removing permissions") } } @@ -650,7 +650,7 @@ func restorePermissions( np, err := service.Client().DrivesById(driveID).ItemsById(itemID).Invite().Post(ctx, pbody, nil) if err != nil { - return permissionIDMappings, clues.Wrap(err, "setting permissions").WithClues(ctx).With(graph.ErrData(err)...) + return permissionIDMappings, graph.Wrap(ctx, err, "setting permissions") } permissionIDMappings[p.ID] = *np.GetValue()[0].GetId() diff --git a/src/internal/connector/sharepoint/api/pages.go b/src/internal/connector/sharepoint/api/pages.go index 542066085..48c3ca816 100644 --- a/src/internal/connector/sharepoint/api/pages.go +++ b/src/internal/connector/sharepoint/api/pages.go @@ -68,7 +68,7 @@ func GetSitePages( page, err = serv.Client().SitesById(siteID).PagesById(pageID).Get(ctx, opts) if err != nil { - el.AddRecoverable(clues.Wrap(err, "fetching page").WithClues(ctx).With(graph.ErrData(err)...)) + el.AddRecoverable(graph.Wrap(ctx, err, "fetching page")) return } @@ -94,7 +94,7 @@ func FetchPages(ctx context.Context, bs *discover.BetaService, siteID string) ([ for { resp, err = builder.Get(ctx, opts) if err != nil { - return nil, clues.Wrap(err, "fetching site page").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "fetching site page") } for _, entry := range resp.GetValue() { @@ -143,7 +143,7 @@ func DeleteSitePage( ) error { err := serv.Client().SitesById(siteID).PagesById(pageID).Delete(ctx, nil) if err != nil { - return clues.Wrap(err, "deleting page").WithClues(ctx).With(graph.ErrData(err)...) + return graph.Wrap(ctx, err, "deleting page") } return nil @@ -203,7 +203,7 @@ func RestoreSitePage( // See: https://learn.microsoft.com/en-us/graph/api/sitepage-create?view=graph-rest-beta restoredPage, err := service.Client().SitesById(siteID).Pages().Post(ctx, page, nil) if err != nil { - return dii, clues.Wrap(err, "creating page").WithClues(ctx).With(graph.ErrData(err)...) + return dii, graph.Wrap(ctx, err, "creating page") } pageID = ptr.Val(restoredPage.GetId()) @@ -221,7 +221,7 @@ func RestoreSitePage( Publish(). Post(ctx, nil) if err != nil { - return dii, clues.Wrap(err, "publishing page").WithClues(ctx).With(graph.ErrData(err)...) + return dii, graph.Wrap(ctx, err, "publishing page") } dii.SharePoint = PageInfo(restoredPage, int64(len(byteArray))) diff --git a/src/internal/connector/sharepoint/collection.go b/src/internal/connector/sharepoint/collection.go index 2b00fae4e..7affe6d0b 100644 --- a/src/internal/connector/sharepoint/collection.go +++ b/src/internal/connector/sharepoint/collection.go @@ -231,7 +231,7 @@ func (sc *Collection) retrieveLists( break } - byteArray, err := serializeContent(wtr, lst) + byteArray, err := serializeContent(ctx, wtr, lst) if err != nil { el.AddRecoverable(clues.Wrap(err, "serializing list").WithClues(ctx)) continue @@ -292,7 +292,7 @@ func (sc *Collection) retrievePages( break } - byteArray, err := serializeContent(wtr, pg) + byteArray, err := serializeContent(ctx, wtr, pg) if err != nil { el.AddRecoverable(clues.Wrap(err, "serializing page").WithClues(ctx)) continue @@ -317,17 +317,21 @@ func (sc *Collection) retrievePages( return metrics, el.Failure() } -func serializeContent(writer *kw.JsonSerializationWriter, obj absser.Parsable) ([]byte, error) { +func serializeContent( + ctx context.Context, + writer *kw.JsonSerializationWriter, + obj absser.Parsable, +) ([]byte, error) { defer writer.Close() err := writer.WriteObjectValue("", obj) if err != nil { - return nil, clues.Wrap(err, "writing object").With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "writing object") } byteArray, err := writer.GetSerializedContent() if err != nil { - return nil, clues.Wrap(err, "getting content from writer").With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "getting content from writer") } return byteArray, nil diff --git a/src/internal/connector/sharepoint/data_collections.go b/src/internal/connector/sharepoint/data_collections.go index 469822eea..6752fa71c 100644 --- a/src/internal/connector/sharepoint/data_collections.go +++ b/src/internal/connector/sharepoint/data_collections.go @@ -191,7 +191,7 @@ func collectLibraries( // token-based incrementals. odcs, excludes, err := colls.Get(ctx, nil, errs) if err != nil { - return nil, nil, clues.Wrap(err, "getting library").WithClues(ctx).With(graph.ErrData(err)...) + return nil, nil, graph.Wrap(ctx, err, "getting library") } return append(collections, odcs...), excludes, nil diff --git a/src/internal/connector/sharepoint/list.go b/src/internal/connector/sharepoint/list.go index dbbc42c33..41316f140 100644 --- a/src/internal/connector/sharepoint/list.go +++ b/src/internal/connector/sharepoint/list.go @@ -44,7 +44,7 @@ func preFetchLists( for { resp, err := builder.Get(ctx, options) if err != nil { - return nil, clues.Wrap(err, "getting lists").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "getting lists") } for _, entry := range resp.GetValue() { @@ -129,7 +129,7 @@ func loadSiteLists( entry, err = gs.Client().SitesById(siteID).ListsById(id).Get(ctx, nil) if err != nil { - el.AddRecoverable(clues.Wrap(err, "getting site list").WithClues(ctx).With(graph.ErrData(err)...)) + el.AddRecoverable(graph.Wrap(ctx, err, "getting site list")) return } @@ -219,7 +219,7 @@ func fetchListItems( fields, err := newPrefix.Fields().Get(ctx, nil) if err != nil { - el.AddRecoverable(clues.Wrap(err, "getting list fields").WithClues(ctx).With(graph.ErrData(err)...)) + el.AddRecoverable(graph.Wrap(ctx, err, "getting list fields")) continue } @@ -255,7 +255,7 @@ func fetchColumns( for { resp, err := builder.Get(ctx, nil) if err != nil { - return nil, clues.Wrap(err, "getting list columns").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "getting list columns") } cs = append(cs, resp.GetValue()...) @@ -272,7 +272,7 @@ func fetchColumns( for { resp, err := builder.Get(ctx, nil) if err != nil { - return nil, clues.Wrap(err, "getting content columns").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "getting content columns") } cs = append(cs, resp.GetValue()...) @@ -365,7 +365,7 @@ func fetchColumnLinks( for { resp, err := builder.Get(ctx, nil) if err != nil { - return nil, clues.Wrap(err, "getting column links").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "getting column links") } links = append(links, resp.GetValue()...) @@ -392,7 +392,7 @@ func DeleteList( ) error { err := gs.Client().SitesById(siteID).ListsById(listID).Delete(ctx, nil) if err != nil { - return clues.Wrap(err, "deleting list").WithClues(ctx).With(graph.ErrData(err)...) + return graph.Wrap(ctx, err, "deleting list") } return nil diff --git a/src/internal/connector/sharepoint/queries.go b/src/internal/connector/sharepoint/queries.go index 236f90085..4f9010ae5 100644 --- a/src/internal/connector/sharepoint/queries.go +++ b/src/internal/connector/sharepoint/queries.go @@ -6,7 +6,6 @@ import ( absser "github.com/microsoft/kiota-abstractions-go/serialization" mssite "github.com/microsoftgraph/msgraph-sdk-go/sites" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" ) @@ -22,7 +21,7 @@ func GetAllSitesForTenant(ctx context.Context, gs graph.Servicer) (absser.Parsab sites, err := gs.Client().Sites().Get(ctx, options) if err != nil { - return nil, clues.Wrap(err, "getting sites").WithClues(ctx).With(graph.ErrData(err)...) + return nil, graph.Wrap(ctx, err, "getting sites") } return sites, nil diff --git a/src/internal/connector/sharepoint/restore.go b/src/internal/connector/sharepoint/restore.go index 0c77bde18..fa8a7e269 100644 --- a/src/internal/connector/sharepoint/restore.go +++ b/src/internal/connector/sharepoint/restore.go @@ -126,7 +126,7 @@ func createRestoreFolders( // Get Main Drive for Site, Documents mainDrive, err := service.Client().SitesById(siteID).Drive().Get(ctx, nil) if err != nil { - return "", clues.Wrap(err, "getting site drive root").WithClues(ctx).With(graph.ErrData(err)...) + return "", graph.Wrap(ctx, err, "getting site drive root") } return onedrive.CreateRestoreFolders(ctx, service, *mainDrive.GetId(), restoreFolders) @@ -182,7 +182,7 @@ func restoreListItem( // Restore to List base to M365 back store restoredList, err := service.Client().SitesById(siteID).Lists().Post(ctx, newList, nil) if err != nil { - return dii, clues.Wrap(err, "restoring list").WithClues(ctx).With(graph.ErrData(err)...) + return dii, graph.Wrap(ctx, err, "restoring list") } // Uploading of ListItems is conducted after the List is restored @@ -195,10 +195,8 @@ func restoreListItem( Items(). Post(ctx, lItem, nil) if err != nil { - return dii, clues.Wrap(err, "restoring list items"). - With("restored_list_id", ptr.Val(restoredList.GetId())). - WithClues(ctx). - With(graph.ErrData(err)...) + return dii, graph.Wrap(ctx, err, "restoring list items"). + With("restored_list_id", ptr.Val(restoredList.GetId())) } } }