Skip to content

Commit

Permalink
update error wraps to sentinel error
Browse files Browse the repository at this point in the history
  • Loading branch information
xpzouying committed May 16, 2022
1 parent d045bf7 commit 5df83e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions inmemory/kv.go
Expand Up @@ -17,7 +17,6 @@ package inmemory
import (
"time"

"github.com/pkg/errors"
"github.com/xujiajun/nutsdb"
)

Expand Down Expand Up @@ -49,7 +48,7 @@ func (db *DB) Get(bucket string, key []byte) (*nutsdb.Entry, error) {
return entry, nil
}

return nil, errors.Wrapf(nutsdb.ErrKeyNotFound, "not found bucket %s, key %s", bucket, key)
return nil, nutsdb.ErrKeyNotFound
}

func (db *DB) Put(bucket string, key, value []byte, ttl uint32) (err error) {
Expand Down
16 changes: 8 additions & 8 deletions tx_set.go
Expand Up @@ -81,7 +81,7 @@ func (tx *Tx) SAreMembers(bucket string, key []byte, items ...[]byte) (bool, err
return sets.SAreMembers(string(key), items...)
}

return false, ErrBucketAndKey(bucket, key)
return false, ErrBucketNotFound
}

// SIsMember returns if member is a member of the set stored int the bucket at given bucket,key and item.
Expand All @@ -92,12 +92,12 @@ func (tx *Tx) SIsMember(bucket string, key, item []byte) (bool, error) {

if set, ok := tx.db.SetIdx[bucket]; ok {
if !set.SIsMember(string(key), item) {
return false, ErrBucketAndKey(bucket, key)
return false, ErrBucketNotFound
}
return true, nil
}

return false, ErrBucketAndKey(bucket, key)
return false, ErrBucketNotFound
}

// SMembers returns all the members of the set value stored int the bucket at given bucket and key.
Expand All @@ -110,7 +110,7 @@ func (tx *Tx) SMembers(bucket string, key []byte) (list [][]byte, err error) {
return set.SMembers(string(key))
}

return nil, ErrBucketAndKey(bucket, key)
return nil, ErrBucketNotFound

}

Expand All @@ -124,7 +124,7 @@ func (tx *Tx) SHasKey(bucket string, key []byte) (bool, error) {
return set.SHasKey(string(key)), nil
}

return false, ErrBucketAndKey(bucket, key)
return false, ErrBucketNotFound
}

// SPop removes and returns one or more random elements from the set value store in the bucket at given bucket and key.
Expand All @@ -139,7 +139,7 @@ func (tx *Tx) SPop(bucket string, key []byte) ([]byte, error) {
}
}

return nil, ErrBucketAndKey(bucket, key)
return nil, ErrBucketNotFound
}

// SCard returns the set cardinality (number of elements) of the set stored in the bucket at given bucket and key.
Expand All @@ -152,7 +152,7 @@ func (tx *Tx) SCard(bucket string, key []byte) (int, error) {
return set.SCard(string(key)), nil
}

return 0, ErrBucketAndKey(bucket, key)
return 0, ErrBucketNotFound
}

// SDiffByOneBucket returns the members of the set resulting from the difference
Expand All @@ -166,7 +166,7 @@ func (tx *Tx) SDiffByOneBucket(bucket string, key1, key2 []byte) (list [][]byte,
return set.SDiff(string(key1), string(key2))
}

return nil, ErrBucketAndKey(bucket, key1)
return nil, ErrBucketNotFound
}

// SDiffByTwoBuckets returns the members of the set resulting from the difference
Expand Down

0 comments on commit 5df83e8

Please sign in to comment.