diff --git a/src/internal/connector/discovery/discovery.go b/src/internal/connector/discovery/discovery.go index 069eeec9f..df31402b9 100644 --- a/src/internal/connector/discovery/discovery.go +++ b/src/internal/connector/discovery/discovery.go @@ -93,7 +93,7 @@ func User( u, err := gwi.GetByID(ctx, userID) if err != nil { if graph.IsErrUserNotFound(err) { - return nil, nil, clues.Stack(graph.ErrResourceOwnerNotFound).With("user_id", userID) + return nil, nil, clues.Stack(graph.ErrResourceOwnerNotFound, err).With("user_id", userID) } return nil, nil, clues.Wrap(err, "getting user") diff --git a/src/pkg/errs/err.go b/src/pkg/errs/errs.go similarity index 92% rename from src/pkg/errs/err.go rename to src/pkg/errs/errs.go index e00ef8abf..f93e0e51a 100644 --- a/src/pkg/errs/err.go +++ b/src/pkg/errs/errs.go @@ -37,13 +37,13 @@ func Internal(enum errEnum) []error { // Is checks if the provided error contains an internal error that matches // the public error category. func Is(err error, enum errEnum) bool { - esl, ok := internalToExternal[enum] + internalErrs, ok := internalToExternal[enum] if !ok { return false } - for _, e := range esl { - if errors.Is(err, e) { + for _, target := range internalErrs { + if errors.Is(err, target) { return true } } diff --git a/src/pkg/errs/errs_test.go b/src/pkg/errs/errs_test.go index 1ec787efd..789c88658 100644 --- a/src/pkg/errs/errs_test.go +++ b/src/pkg/errs/errs_test.go @@ -3,6 +3,7 @@ package errs import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" @@ -38,8 +39,8 @@ func (suite *ErrUnitSuite) TestInternal() { func (suite *ErrUnitSuite) TestIs() { table := []struct { - is errEnum - input error + target errEnum + err error }{ {RepoAlreadyExists, repository.ErrorRepoAlreadyExists}, {BackupNotFound, repository.ErrorBackupNotFound}, @@ -47,9 +48,24 @@ func (suite *ErrUnitSuite) TestIs() { {ResourceOwnerNotFound, graph.ErrResourceOwnerNotFound}, } for _, test := range table { - suite.Run(string(test.is), func() { - assert.True(suite.T(), Is(test.input, test.is)) - assert.False(suite.T(), Is(assert.AnError, test.is)) + suite.Run(string(test.target), func() { + var ( + w = clues.Wrap(test.err, "wrap") + s = clues.Stack(test.err) + es = clues.Stack(assert.AnError, test.err) + se = clues.Stack(test.err, assert.AnError) + sw = clues.Stack(assert.AnError, w) + ws = clues.Stack(w, assert.AnError) + ) + + assert.True(suite.T(), Is(test.err, test.target)) + assert.True(suite.T(), Is(w, test.target)) + assert.True(suite.T(), Is(s, test.target)) + assert.True(suite.T(), Is(es, test.target)) + assert.True(suite.T(), Is(se, test.target)) + assert.True(suite.T(), Is(sw, test.target)) + assert.True(suite.T(), Is(ws, test.target)) + assert.False(suite.T(), Is(assert.AnError, test.target)) }) } } diff --git a/src/pkg/services/m365/api/users.go b/src/pkg/services/m365/api/users.go index 32d2c2aba..d6fc71aed 100644 --- a/src/pkg/services/m365/api/users.go +++ b/src/pkg/services/m365/api/users.go @@ -263,7 +263,7 @@ func (c Users) GetInfo(ctx context.Context, userID string) (*UserInfo, error) { if _, err := c.GetMailFolders(ctx, userID, options); err != nil { if graph.IsErrUserNotFound(err) { logger.CtxErr(ctx, err).Error("user not found") - return nil, err + return nil, graph.Stack(ctx, clues.Stack(graph.ErrResourceOwnerNotFound, err)) } if !graph.IsErrExchangeMailFolderNotFound(err) ||