Sfoglia il codice sorgente

Merge pull request #39 from chenchun/better_error_msg

Notify user of supported backend storage
Alexandre Beslic 10 anni fa
parent
commit
518ab82942

+ 1 - 1
libnetwork/internal/kvstore/kvstore.go

@@ -20,7 +20,7 @@ const (
 
 var (
 	// ErrNotSupported is thrown when the backend k/v store is not supported by libkv
-	ErrNotSupported = errors.New("Backend storage not supported yet, please choose another one")
+	ErrNotSupported = errors.New("Backend storage not supported yet, please choose one of")
 	// ErrNotImplemented is thrown when a method is not implemented by the current backend
 	ErrNotImplemented = errors.New("Call not implemented in current backend")
 	// ErrNotReachable is thrown when the API cannot be reached for issuing common store operations

+ 13 - 1
libnetwork/internal/kvstore/kvstore_manage.go

@@ -62,6 +62,10 @@
 package libkv
 
 import (
+	"fmt"
+	"sort"
+	"strings"
+
 	"github.com/docker/libkv/store"
 	"github.com/docker/libkv/store/consul"
 	"github.com/docker/libkv/store/etcd"
@@ -78,6 +82,14 @@ var (
 		store.ETCD:   etcd.New,
 		store.ZK:     zookeeper.New,
 	}
+	supportedBackend = func() string {
+		keys := make([]string, 0, len(initializers))
+		for k := range initializers {
+			keys = append(keys, string(k))
+		}
+		sort.Strings(keys)
+		return strings.Join(keys, ", ")
+	}()
 )
 
 // NewStore creates a an instance of store
@@ -86,5 +98,5 @@ func NewStore(backend store.Backend, addrs []string, options *store.Config) (sto
 		return init(addrs, options)
 	}
 
-	return nil, store.ErrNotSupported
+	return nil, fmt.Errorf("%s %s", store.ErrNotSupported.Error(), supportedBackend)
 }