Selaa lähdekoodia

improve error for getStore()

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Akihiro Suda 8 vuotta sitten
vanhempi
commit
79bf46fd79
2 muutettua tiedostoa jossa 10 lisäystä ja 2 poistoa
  1. 8 0
      libnetwork/error.go
  2. 2 2
      libnetwork/store.go

+ 8 - 0
libnetwork/error.go

@@ -183,3 +183,11 @@ func (mr ManagerRedirectError) Error() string {
 
 // Maskable denotes the type of this error
 func (mr ManagerRedirectError) Maskable() {}
+
+// ErrDataStoreNotInitialized is returned if an invalid data scope is passed
+// for getting data store
+type ErrDataStoreNotInitialized string
+
+func (dsni ErrDataStoreNotInitialized) Error() string {
+	return fmt.Sprintf("datastore for scope %q is not initialized", string(dsni))
+}

+ 2 - 2
libnetwork/store.go

@@ -225,7 +225,7 @@ func (n *network) getEndpointsFromStore() ([]*endpoint, error) {
 func (c *controller) updateToStore(kvObject datastore.KVObject) error {
 	cs := c.getStore(kvObject.DataScope())
 	if cs == nil {
-		return fmt.Errorf("datastore for scope %q is not initialized ", kvObject.DataScope())
+		return ErrDataStoreNotInitialized(kvObject.DataScope())
 	}
 
 	if err := cs.PutObjectAtomic(kvObject); err != nil {
@@ -241,7 +241,7 @@ func (c *controller) updateToStore(kvObject datastore.KVObject) error {
 func (c *controller) deleteFromStore(kvObject datastore.KVObject) error {
 	cs := c.getStore(kvObject.DataScope())
 	if cs == nil {
-		return fmt.Errorf("datastore for scope %q is not initialized ", kvObject.DataScope())
+		return ErrDataStoreNotInitialized(kvObject.DataScope())
 	}
 
 retry: