minor errs cleanup (#3234)
some code cleanup that happened while investigating a bug repro --- #### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🧹 Tech Debt/Cleanup #### Test Plan - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
b8e868c05b
commit
1cd592d216
@ -93,7 +93,7 @@ func User(
|
|||||||
u, err := gwi.GetByID(ctx, userID)
|
u, err := gwi.GetByID(ctx, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if graph.IsErrUserNotFound(err) {
|
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")
|
return nil, nil, clues.Wrap(err, "getting user")
|
||||||
|
|||||||
@ -37,13 +37,13 @@ func Internal(enum errEnum) []error {
|
|||||||
// Is checks if the provided error contains an internal error that matches
|
// Is checks if the provided error contains an internal error that matches
|
||||||
// the public error category.
|
// the public error category.
|
||||||
func Is(err error, enum errEnum) bool {
|
func Is(err error, enum errEnum) bool {
|
||||||
esl, ok := internalToExternal[enum]
|
internalErrs, ok := internalToExternal[enum]
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, e := range esl {
|
for _, target := range internalErrs {
|
||||||
if errors.Is(err, e) {
|
if errors.Is(err, target) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,6 +3,7 @@ package errs
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/alcionai/clues"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
@ -38,8 +39,8 @@ func (suite *ErrUnitSuite) TestInternal() {
|
|||||||
|
|
||||||
func (suite *ErrUnitSuite) TestIs() {
|
func (suite *ErrUnitSuite) TestIs() {
|
||||||
table := []struct {
|
table := []struct {
|
||||||
is errEnum
|
target errEnum
|
||||||
input error
|
err error
|
||||||
}{
|
}{
|
||||||
{RepoAlreadyExists, repository.ErrorRepoAlreadyExists},
|
{RepoAlreadyExists, repository.ErrorRepoAlreadyExists},
|
||||||
{BackupNotFound, repository.ErrorBackupNotFound},
|
{BackupNotFound, repository.ErrorBackupNotFound},
|
||||||
@ -47,9 +48,24 @@ func (suite *ErrUnitSuite) TestIs() {
|
|||||||
{ResourceOwnerNotFound, graph.ErrResourceOwnerNotFound},
|
{ResourceOwnerNotFound, graph.ErrResourceOwnerNotFound},
|
||||||
}
|
}
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.Run(string(test.is), func() {
|
suite.Run(string(test.target), func() {
|
||||||
assert.True(suite.T(), Is(test.input, test.is))
|
var (
|
||||||
assert.False(suite.T(), Is(assert.AnError, test.is))
|
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))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 _, err := c.GetMailFolders(ctx, userID, options); err != nil {
|
||||||
if graph.IsErrUserNotFound(err) {
|
if graph.IsErrUserNotFound(err) {
|
||||||
logger.CtxErr(ctx, err).Error("user not found")
|
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) ||
|
if !graph.IsErrExchangeMailFolderNotFound(err) ||
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user