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