diff options
author | Rodolfo Carvalho <rhcarvalho@gmail.com> | 2015-12-10 18:39:03 +0100 |
---|---|---|
committer | Rodolfo Carvalho <rhcarvalho@gmail.com> | 2015-12-10 18:39:03 +0100 |
commit | 058a7ab3475728df50656699387b985b3a2537ed (patch) | |
tree | 9ef288011fb89734bb8509012624eea5badea884 /db.go | |
parent | Merge pull request #467 from boltdb/readme-coalescer (diff) | |
download | dedo-058a7ab3475728df50656699387b985b3a2537ed.tar.gz dedo-058a7ab3475728df50656699387b985b3a2537ed.tar.xz |
Make bolt.Open return the documented errors
- ErrInvalid is returned when a data file is not a Bolt-formatted
database.
- ErrVersionMismatch is returned when the data file was created with a
different version of Bolt.
- ErrChecksum is returned when either meta page checksum does not match.
Also:
- Do not wrap errors from os.Stat, so that a caller could handle os.Stat
errors just like it can handle errors from os.Open that bolt.Open
might return.
- Name tests consistently, following the pattern "TestOpen_*".
- Remove deferred calls to `os.Remove(path)`.
The calls are not only unnecessary, but also in all cases `os.Remove`
returns an error that is ignored. All those calls are meant to remove
a file that was already removed by `tmpfile()`.
- Combine "bad path" tests and use filepath.Join to build the path.
Diffstat (limited to 'db.go')
-rw-r--r-- | db.go | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -177,7 +177,7 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) { // Initialize the database if it doesn't exist. if info, err := db.file.Stat(); err != nil { - return nil, fmt.Errorf("stat error: %s", err) + return nil, err } else if info.Size() == 0 { // Initialize new files with meta pages. if err := db.init(); err != nil { @@ -189,7 +189,7 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) { if _, err := db.file.ReadAt(buf[:], 0); err == nil { m := db.pageInBuffer(buf[:], 0).meta() if err := m.validate(); err != nil { - return nil, fmt.Errorf("meta0 error: %s", err) + return nil, err } db.pageSize = int(m.pageSize) } @@ -253,10 +253,10 @@ func (db *DB) mmap(minsz int) error { // Validate the meta pages. if err := db.meta0.validate(); err != nil { - return fmt.Errorf("meta0 error: %s", err) + return err } if err := db.meta1.validate(); err != nil { - return fmt.Errorf("meta1 error: %s", err) + return err } return nil |