| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 1 | // Package errors defines the error variables that may be returned |
| 2 | // during bbolt operations. |
| 3 | package errors |
| 4 | |
| 5 | import "errors" |
| 6 | |
| 7 | // These errors can be returned when opening or calling methods on a DB. |
| 8 | var ( |
| 9 | // ErrDatabaseNotOpen is returned when a DB instance is accessed before it |
| 10 | // is opened or after it is closed. |
| 11 | ErrDatabaseNotOpen = errors.New("database not open") |
| 12 | |
| 13 | // ErrInvalid is returned when both meta pages on a database are invalid. |
| 14 | // This typically occurs when a file is not a bolt database. |
| 15 | ErrInvalid = errors.New("invalid database") |
| 16 | |
| 17 | // ErrInvalidMapping is returned when the database file fails to get mapped. |
| 18 | ErrInvalidMapping = errors.New("database isn't correctly mapped") |
| 19 | |
| 20 | // ErrVersionMismatch is returned when the data file was created with a |
| 21 | // different version of Bolt. |
| 22 | ErrVersionMismatch = errors.New("version mismatch") |
| 23 | |
| 24 | // ErrChecksum is returned when a checksum mismatch occurs on either of the two meta pages. |
| 25 | ErrChecksum = errors.New("checksum error") |
| 26 | |
| 27 | // ErrTimeout is returned when a database cannot obtain an exclusive lock |
| 28 | // on the data file after the timeout passed to Open(). |
| 29 | ErrTimeout = errors.New("timeout") |
| 30 | ) |
| 31 | |
| 32 | // These errors can occur when beginning or committing a Tx. |
| 33 | var ( |
| 34 | // ErrTxNotWritable is returned when performing a write operation on a |
| 35 | // read-only transaction. |
| 36 | ErrTxNotWritable = errors.New("tx not writable") |
| 37 | |
| 38 | // ErrTxClosed is returned when committing or rolling back a transaction |
| 39 | // that has already been committed or rolled back. |
| 40 | ErrTxClosed = errors.New("tx closed") |
| 41 | |
| 42 | // ErrDatabaseReadOnly is returned when a mutating transaction is started on a |
| 43 | // read-only database. |
| 44 | ErrDatabaseReadOnly = errors.New("database is in read-only mode") |
| 45 | |
| 46 | // ErrFreePagesNotLoaded is returned when a readonly transaction without |
| 47 | // preloading the free pages is trying to access the free pages. |
| 48 | ErrFreePagesNotLoaded = errors.New("free pages are not pre-loaded") |
| 49 | ) |
| 50 | |
| 51 | // These errors can occur when putting or deleting a value or a bucket. |
| 52 | var ( |
| 53 | // ErrBucketNotFound is returned when trying to access a bucket that has |
| 54 | // not been created yet. |
| 55 | ErrBucketNotFound = errors.New("bucket not found") |
| 56 | |
| 57 | // ErrBucketExists is returned when creating a bucket that already exists. |
| 58 | ErrBucketExists = errors.New("bucket already exists") |
| 59 | |
| 60 | // ErrBucketNameRequired is returned when creating a bucket with a blank name. |
| 61 | ErrBucketNameRequired = errors.New("bucket name required") |
| 62 | |
| 63 | // ErrKeyRequired is returned when inserting a zero-length key. |
| 64 | ErrKeyRequired = errors.New("key required") |
| 65 | |
| 66 | // ErrKeyTooLarge is returned when inserting a key that is larger than MaxKeySize. |
| 67 | ErrKeyTooLarge = errors.New("key too large") |
| 68 | |
| 69 | // ErrValueTooLarge is returned when inserting a value that is larger than MaxValueSize. |
| 70 | ErrValueTooLarge = errors.New("value too large") |
| 71 | |
| 72 | // ErrIncompatibleValue is returned when trying to create or delete a bucket |
| 73 | // on an existing non-bucket key or when trying to create or delete a |
| 74 | // non-bucket key on an existing bucket key. |
| 75 | ErrIncompatibleValue = errors.New("incompatible value") |
| 76 | |
| 77 | // ErrSameBuckets is returned when trying to move a sub-bucket between |
| 78 | // source and target buckets, while source and target buckets are the same. |
| 79 | ErrSameBuckets = errors.New("the source and target are the same bucket") |
| 80 | |
| 81 | // ErrDifferentDB is returned when trying to move a sub-bucket between |
| 82 | // source and target buckets, while source and target buckets are in different database files. |
| 83 | ErrDifferentDB = errors.New("the source and target buckets are in different database files") |
| 84 | ) |