From f26c4862a57c610cc2f7aab15c95103117eb065d Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 19 Jul 2016 10:22:22 +0100 Subject: [PATCH] Return if any errors when initialising data stores --- kvs/boltdb/main.go | 3 +++ kvs/db.go | 12 +++++++++--- kvs/mysql/main.go | 3 +++ kvs/pgsql/main.go | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/kvs/boltdb/main.go b/kvs/boltdb/main.go index 74387a2d..8f5a55b1 100644 --- a/kvs/boltdb/main.go +++ b/kvs/boltdb/main.go @@ -36,6 +36,9 @@ func New(opts *cnf.Options) (ds kvs.DS, err error) { path := strings.TrimLeft(opts.DB.Path, "boltdb://") db, err = bolt.Open(path, 0666, nil) + if err != nil { + return + } db.Update(func(tx *bolt.Tx) error { tx.CreateBucketIfNotExists(bucket) diff --git a/kvs/db.go b/kvs/db.go index f1694e04..cfa6ce13 100644 --- a/kvs/db.go +++ b/kvs/db.go @@ -35,15 +35,21 @@ func New(opts *cnf.Options) (db *DB, err error) { var ds DS if strings.HasPrefix(opts.DB.Path, "boltdb://") { - ds, err = stores["boltdb"](opts) + if ds, err = stores["boltdb"](opts); err != nil { + return + } } if strings.HasPrefix(opts.DB.Path, "mysql://") { - ds, err = stores["mysql"](opts) + if ds, err = stores["mysql"](opts); err != nil { + return + } } if strings.HasPrefix(opts.DB.Path, "pgsql://") { - ds, err = stores["pgsql"](opts) + if ds, err = stores["pgsql"](opts); err != nil { + return + } } db = &DB{ds: ds} diff --git a/kvs/mysql/main.go b/kvs/mysql/main.go index 63fdfdab..7e8e7b6c 100644 --- a/kvs/mysql/main.go +++ b/kvs/mysql/main.go @@ -35,6 +35,9 @@ func New(opts *cnf.Options) (ds kvs.DS, err error) { path := strings.TrimLeft(opts.DB.Path, "mysql://") db, err = sql.Open("mysql", path) + if err != nil { + return + } return &DS{db: db, ck: opts.DB.Key}, err diff --git a/kvs/pgsql/main.go b/kvs/pgsql/main.go index 5b69a0fe..2cf295d3 100644 --- a/kvs/pgsql/main.go +++ b/kvs/pgsql/main.go @@ -35,6 +35,9 @@ func New(opts *cnf.Options) (ds kvs.DS, err error) { path := strings.TrimLeft(opts.DB.Path, "pgsql://") db, err = sql.Open("postgres", path) + if err != nil { + return + } return &DS{db: db, ck: opts.DB.Key}, err