From 058a7ab3475728df50656699387b985b3a2537ed Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Thu, 10 Dec 2015 18:39:03 +0100 Subject: 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. --- db.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'db.go') diff --git a/db.go b/db.go index 4ff07ae..d5ad715 100644 --- a/db.go +++ b/db.go @@ -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 -- cgit v1.2.3