From 369a92c71f0ce08598f9707e5ae2da52bc8fa069 Mon Sep 17 00:00:00 2001 From: Kit Patella Date: Fri, 17 Jul 2020 13:03:36 -0700 Subject: [PATCH 1/2] command: fix cas put when index=0 and better errors in put and delete --- command/kv/del/kv_delete.go | 2 +- command/kv/put/kv_put.go | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/command/kv/del/kv_delete.go b/command/kv/del/kv_delete.go index 78e1967ee..62fe49f7c 100644 --- a/command/kv/del/kv_delete.go +++ b/command/kv/del/kv_delete.go @@ -78,7 +78,7 @@ func (c *cmd) Run(args []string) int { // ModifyIndex is required for CAS if c.cas && c.modifyIndex == 0 { - c.UI.Error("Must specify -modify-index with -cas!") + c.UI.Error("Cannot delete a key that does not exist. Provide a -modify-index greater than than 0.") return 1 } diff --git a/command/kv/put/kv_put.go b/command/kv/put/kv_put.go index 0f416273d..55c73439d 100644 --- a/command/kv/put/kv_put.go +++ b/command/kv/put/kv_put.go @@ -99,12 +99,6 @@ func (c *cmd) Run(args []string) int { return 1 } - // ModifyIndex is required for CAS - if c.cas && c.modifyIndex == 0 { - c.UI.Error("Must specify -modify-index with -cas!") - return 1 - } - // Create and test the HTTP client client, err := c.http.APIClient() if err != nil { @@ -127,6 +121,10 @@ func (c *cmd) Run(args []string) int { c.UI.Error(fmt.Sprintf("Error! Did not write to %s: %s", key, err)) return 1 } + if !ok && c.modifyIndex == 0 { + c.UI.Error(fmt.Sprintf("Error! Did not write to %s: CAS performed with index=0 and key already exists.", key)) + return 1 + } if !ok { c.UI.Error(fmt.Sprintf("Error! Did not write to %s: CAS failed", key)) return 1 From b47fcf728229fd6ea21725d58dc6d2a6e7848c83 Mon Sep 17 00:00:00 2001 From: Kit Patella Date: Mon, 20 Jul 2020 09:15:25 -0700 Subject: [PATCH 2/2] command/kv: remove error case in put and edit error message for delete --- command/kv/del/kv_delete_test.go | 2 +- command/kv/put/kv_put_test.go | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/command/kv/del/kv_delete_test.go b/command/kv/del/kv_delete_test.go index aeba73445..982a90685 100644 --- a/command/kv/del/kv_delete_test.go +++ b/command/kv/del/kv_delete_test.go @@ -32,7 +32,7 @@ func TestKVDeleteCommand_Validation(t *testing.T) { }, "-cas no -modify-index": { []string{"-cas", "foo"}, - "Must specify -modify-index", + "Cannot delete a key that does not exist", }, "-modify-index no -cas": { []string{"-modify-index", "2", "foo"}, diff --git a/command/kv/put/kv_put_test.go b/command/kv/put/kv_put_test.go index 12c99d6f3..eec776b4e 100644 --- a/command/kv/put/kv_put_test.go +++ b/command/kv/put/kv_put_test.go @@ -39,10 +39,6 @@ func TestKVPutCommand_Validation(t *testing.T) { []string{"-release", "foo"}, "Missing -session", }, - "-cas no -modify-index": { - []string{"-cas", "foo"}, - "Must specify -modify-index", - }, "no key": { []string{}, "Missing KEY argument",