handle error when deleting non existing key
This commit is contained in:
@@ -140,6 +140,9 @@ func (t *Query) Delete(np *VaultService, success *bool) error {
|
||||
err := val.Delete(np.Service)
|
||||
if err != nil {
|
||||
*success = false
|
||||
if err == storage.ErrNotFound {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
"errors"
|
||||
|
||||
"github.com/ipfs/go-datastore/query"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
@@ -18,6 +19,8 @@ import (
|
||||
. "github.com/k4lipso/pentapass/internal/log"
|
||||
)
|
||||
|
||||
var ErrNotFound error = errors.New("Not found")
|
||||
|
||||
type Vault struct {
|
||||
ID string
|
||||
Datastore *crdt.Datastore
|
||||
@@ -73,8 +76,15 @@ func (n *Vault) Put(k string, v string) error {
|
||||
}
|
||||
|
||||
func (n *Vault) Delete(k string) error {
|
||||
_, err := n.GetPassword(k)
|
||||
|
||||
if err != nil {
|
||||
return ErrNotFound
|
||||
}
|
||||
|
||||
key := ds.NewKey(k)
|
||||
err := n.Datastore.Delete(n.ctx, key)
|
||||
|
||||
err = n.Datastore.Delete(n.ctx, key)
|
||||
|
||||
if err != nil {
|
||||
printErr(err)
|
||||
|
||||
Reference in New Issue
Block a user