mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-18 19:15:19 +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()
|
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" }
|
func IsClosed(err error) bool { return errors.Is(err, errClosed) }
|
||||||
|
func IsNotFound(err error) bool { return errors.Is(err, errNotFound) }
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// releaser manages counting on top of a waitgroup
|
// releaser manages counting on top of a waitgroup
|
||||||
type releaser struct {
|
type releaser struct {
|
||||||
@ -183,7 +173,7 @@ func (cg *closeWaitGroup) Add(i int) error {
|
|||||||
cg.closeMut.RLock()
|
cg.closeMut.RLock()
|
||||||
defer cg.closeMut.RUnlock()
|
defer cg.closeMut.RUnlock()
|
||||||
if cg.closed {
|
if cg.closed {
|
||||||
return &errClosed{}
|
return errClosed
|
||||||
}
|
}
|
||||||
cg.WaitGroup.Add(i)
|
cg.WaitGroup.Add(i)
|
||||||
return nil
|
return nil
|
||||||
|
@ -223,11 +223,11 @@ func (it *leveldbIterator) Error() error {
|
|||||||
|
|
||||||
// wrapLeveldbErr wraps errors so that the backend package can recognize them
|
// wrapLeveldbErr wraps errors so that the backend package can recognize them
|
||||||
func wrapLeveldbErr(err error) error {
|
func wrapLeveldbErr(err error) error {
|
||||||
if err == leveldb.ErrClosed {
|
switch err {
|
||||||
return &errClosed{}
|
case leveldb.ErrClosed:
|
||||||
}
|
return errClosed
|
||||||
if err == leveldb.ErrNotFound {
|
case leveldb.ErrNotFound:
|
||||||
return &errNotFound{}
|
return errNotFound
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user