improve error for getStore()

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2017-04-05 05:37:58 +00:00
parent c3036bcc36
commit 79bf46fd79
2 changed files with 10 additions and 2 deletions

View File

@ -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))
}

View File

@ -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: