Skip to content

Commit

Permalink
Use errors.New instead of fmt.Errorf (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyahui authored Aug 20, 2023
1 parent caa3415 commit 74db1b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions bigcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bigcache

import (
"context"
"errors"
"fmt"
"time"
)
Expand Down Expand Up @@ -57,16 +58,16 @@ func NewBigCache(config Config) (*BigCache, error) {

func newBigCache(ctx context.Context, config Config, clock clock) (*BigCache, error) {
if !isPowerOfTwo(config.Shards) {
return nil, fmt.Errorf("Shards number must be power of two")
return nil, errors.New("Shards number must be power of two")
}
if config.MaxEntrySize < 0 {
return nil, fmt.Errorf("MaxEntrySize must be >= 0")
return nil, errors.New("MaxEntrySize must be >= 0")
}
if config.MaxEntriesInWindow < 0 {
return nil, fmt.Errorf("MaxEntriesInWindow must be >= 0")
return nil, errors.New("MaxEntriesInWindow must be >= 0")
}
if config.HardMaxCacheSize < 0 {
return nil, fmt.Errorf("HardMaxCacheSize must be >= 0")
return nil, errors.New("HardMaxCacheSize must be >= 0")
}

if config.Hasher == nil {
Expand Down
8 changes: 4 additions & 4 deletions shard.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package bigcache

import (
"fmt"
"errors"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -146,7 +146,7 @@ func (s *cacheShard) set(key string, hashedKey uint64, entry []byte) error {
}
if s.removeOldestEntry(NoSpace) != nil {
s.lock.Unlock()
return fmt.Errorf("entry is bigger than max shard size")
return errors.New("entry is bigger than max shard size")
}
}
}
Expand All @@ -168,7 +168,7 @@ func (s *cacheShard) addNewWithoutLock(key string, hashedKey uint64, entry []byt
return nil
}
if s.removeOldestEntry(NoSpace) != nil {
return fmt.Errorf("entry is bigger than max shard size")
return errors.New("entry is bigger than max shard size")
}
}
}
Expand All @@ -192,7 +192,7 @@ func (s *cacheShard) setWrappedEntryWithoutLock(currentTimestamp uint64, w []byt
return nil
}
if s.removeOldestEntry(NoSpace) != nil {
return fmt.Errorf("entry is bigger than max shard size")
return errors.New("entry is bigger than max shard size")
}
}
}
Expand Down

0 comments on commit 74db1b9

Please sign in to comment.