mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
lib/db: Make err(Closed|NotFound) values (#8215)
This commit is contained in:
parent
6862dd04ab
commit
d0fd6c6c82
@ -133,23 +133,13 @@ func OpenMemory() Backend {
|
||||
return OpenLevelDBMemory()
|
||||
}
|
||||
|
||||
type errClosed struct{}
|
||||
var (
|
||||
errClosed = errors.New("database is closed")
|
||||
errNotFound = errors.New("key not found")
|
||||
)
|
||||
|
||||
func (*errClosed) Error() string { return "database is closed" }
|
||||
|
||||
type errNotFound struct{}
|
||||
|
||||
func (*errNotFound) Error() string { return "key not found" }
|
||||
|
||||
func IsClosed(err error) bool {
|
||||
e := &errClosed{}
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
func IsNotFound(err error) bool {
|
||||
e := &errNotFound{}
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
func IsClosed(err error) bool { return errors.Is(err, errClosed) }
|
||||
func IsNotFound(err error) bool { return errors.Is(err, errNotFound) }
|
||||
|
||||
// releaser manages counting on top of a waitgroup
|
||||
type releaser struct {
|
||||
@ -183,7 +173,7 @@ func (cg *closeWaitGroup) Add(i int) error {
|
||||
cg.closeMut.RLock()
|
||||
defer cg.closeMut.RUnlock()
|
||||
if cg.closed {
|
||||
return &errClosed{}
|
||||
return errClosed
|
||||
}
|
||||
cg.WaitGroup.Add(i)
|
||||
return nil
|
||||
|
@ -223,11 +223,11 @@ func (it *leveldbIterator) Error() error {
|
||||
|
||||
// wrapLeveldbErr wraps errors so that the backend package can recognize them
|
||||
func wrapLeveldbErr(err error) error {
|
||||
if err == leveldb.ErrClosed {
|
||||
return &errClosed{}
|
||||
}
|
||||
if err == leveldb.ErrNotFound {
|
||||
return &errNotFound{}
|
||||
switch err {
|
||||
case leveldb.ErrClosed:
|
||||
return errClosed
|
||||
case leveldb.ErrNotFound:
|
||||
return errNotFound
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user