diff --git a/pkg/storage/utils/indexer/errors/errors.go b/pkg/storage/utils/indexer/errors/errors.go index 91cc3b78b9..d7bb66e339 100644 --- a/pkg/storage/utils/indexer/errors/errors.go +++ b/pkg/storage/utils/indexer/errors/errors.go @@ -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 -} +// IsAlreadyExists implements the IsAlreadyExists interface. +func (e *AlreadyExistsErr) IsAlreadyExists() {} // NotFoundErr implements the Error interface. type NotFoundErr struct { @@ -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() {} diff --git a/pkg/storage/utils/indexer/index/unique_test.go b/pkg/storage/utils/indexer/index/unique_test.go index 1110274b5f..b08e089061 100644 --- a/pkg/storage/utils/indexer/index/unique_test.go +++ b/pkg/storage/utils/indexer/index/unique_test.go @@ -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) diff --git a/pkg/storage/utils/indexer/indexer.go b/pkg/storage/utils/indexer/indexer.go index 9806aa5a4f..8b48b12960 100644 --- a/pkg/storage/utils/indexer/indexer.go +++ b/pkg/storage/utils/indexer/indexer.go @@ -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" @@ -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 } @@ -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 }