refactor garph.ErrData
This commit is contained in:
parent
27e9661e63
commit
3de82f9a5b
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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)))
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user