1 // Copyright (c) 2014, Suryandaru Triandana <syndtr@gmail.com>
2 // All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
7 // Package errors provides common error types used throughout leveldb.
14 "github.com/syndtr/goleveldb/leveldb/storage"
15 "github.com/syndtr/goleveldb/leveldb/util"
20 ErrNotFound = New("leveldb: not found")
21 ErrReleased = util.ErrReleased
22 ErrHasReleaser = util.ErrHasReleaser
25 // New returns an error that formats as the given text.
26 func New(text string) error {
27 return errors.New(text)
30 // ErrCorrupted is the type that wraps errors that indicate corruption in
32 type ErrCorrupted struct {
37 func (e *ErrCorrupted) Error() string {
39 return fmt.Sprintf("%v [file=%v]", e.Err, e.Fd)
44 // NewErrCorrupted creates new ErrCorrupted error.
45 func NewErrCorrupted(fd storage.FileDesc, err error) error {
46 return &ErrCorrupted{fd, err}
49 // IsCorrupted returns a boolean indicating whether the error is indicating
51 func IsCorrupted(err error) bool {
55 case *storage.ErrCorrupted:
61 // ErrMissingFiles is the type that indicating a corruption due to missing
62 // files. ErrMissingFiles always wrapped with ErrCorrupted.
63 type ErrMissingFiles struct {
64 Fds []storage.FileDesc
67 func (e *ErrMissingFiles) Error() string { return "file missing" }
69 // SetFd sets 'file info' of the given error with the given file.
70 // Currently only ErrCorrupted is supported, otherwise will do nothing.
71 func SetFd(err error, fd storage.FileDesc) error {
72 switch x := err.(type) {