Skip to content

Commit

Permalink
Fix error type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Mar 9, 2022
1 parent c6e00d3 commit aab0ac6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
14 changes: 4 additions & 10 deletions pkg/storage/utils/indexer/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ func (e *AlreadyExistsErr) Error() string {
return fmt.Sprintf("%s with %s=%s does already exist", e.TypeName, e.IndexBy.String(), e.Value)
}

// IsAlreadyExistsErr checks whether an error is of type AlreadyExistsErr.
func IsAlreadyExistsErr(e error) bool {
_, ok := e.(*AlreadyExistsErr)
return ok
}
// AlreadyExists implements the IsAlreadyExists interface.
func (e *AlreadyExistsErr) IsAlreadyExists() {}

// NotFoundErr implements the Error interface.
type NotFoundErr struct {
Expand All @@ -50,8 +47,5 @@ func (e *NotFoundErr) Error() string {
return fmt.Sprintf("%s with %s=%s not found", e.TypeName, e.IndexBy.String(), e.Value)
}

// IsNotFoundErr checks whether an error is of type IsNotFoundErr.
func IsNotFoundErr(e error) bool {
_, ok := e.(*NotFoundErr)
return ok
}
// IsNotFound implements the IsNotFound interface.
func (e *NotFoundErr) IsNotFound() {}
5 changes: 0 additions & 5 deletions pkg/storage/utils/indexer/index/unique_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ func TestUniqueIndexSearch(t *testing.T) {
_ = os.RemoveAll(dataDir)
}

func TestErrors(t *testing.T) {
assert.True(t, errors.IsAlreadyExistsErr(&errors.AlreadyExistsErr{}))
assert.True(t, errors.IsNotFoundErr(&errors.NotFoundErr{}))
}

func getUniqueIdxSut(t *testing.T, indexBy option.IndexBy, entityType interface{}) (index.Index, string) {
dataPath, _ := WriteIndexTestData(Data, "ID", "")
storage, err := metadata.NewDiskStorage(dataPath)
Expand Down
5 changes: 2 additions & 3 deletions pkg/storage/utils/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/iancoleman/strcase"

"github.com/cs3org/reva/v2/pkg/errtypes"
errorspkg "github.com/cs3org/reva/v2/pkg/storage/utils/indexer/errors"
"github.com/cs3org/reva/v2/pkg/storage/utils/indexer/index"
"github.com/cs3org/reva/v2/pkg/storage/utils/indexer/option"
"github.com/cs3org/reva/v2/pkg/storage/utils/metadata"
Expand Down Expand Up @@ -149,7 +148,7 @@ func (i *Indexer) FindBy(t interface{}, findBy, val string) ([]string, error) {
idxVal := val
res, err := idx.Lookup(idxVal)
if err != nil {
if _, ok := err.(errtypes.NotFound); ok {
if _, ok := err.(errtypes.IsNotFound); ok {
continue
}

Expand Down Expand Up @@ -211,7 +210,7 @@ func (i *Indexer) FindByPartial(t interface{}, field string, pattern string) ([]
for _, idx := range fields.IndicesByField[strcase.ToCamel(field)] {
res, err := idx.Search(pattern)
if err != nil {
if errorspkg.IsNotFoundErr(err) {
if _, ok := err.(errtypes.IsNotFound); ok {
continue
}

Expand Down

0 comments on commit aab0ac6

Please sign in to comment.