From ae3d6492b0af9bc052fccc082aafb79b614fb2a5 Mon Sep 17 00:00:00 2001 From: Boyang Lyu Date: Thu, 7 Nov 2024 17:05:20 +0800 Subject: [PATCH 1/3] add error code reporting in the store command Signed-off-by: Boyang Lyu --- tools/pd-ctl/pdctl/command/store_command.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/pd-ctl/pdctl/command/store_command.go b/tools/pd-ctl/pdctl/command/store_command.go index 188d36e25de..48aeae253da 100644 --- a/tools/pd-ctl/pdctl/command/store_command.go +++ b/tools/pd-ctl/pdctl/command/store_command.go @@ -19,6 +19,7 @@ import ( "encoding/json" "fmt" "net/http" + "os" "path" "strconv" "strings" @@ -381,6 +382,7 @@ func deleteStoreCommandFunc(cmd *cobra.Command, args []string) { func deleteStoreCommandByAddrFunc(cmd *cobra.Command, args []string) { id := getStoreID(cmd, args, false) if id == -1 { + os.Exit(1) return } // delete store by its ID @@ -388,6 +390,7 @@ func deleteStoreCommandByAddrFunc(cmd *cobra.Command, args []string) { _, err := doRequest(cmd, prefix, http.MethodDelete, http.Header{}) if err != nil { cmd.Printf("Failed to delete store %s: %s\n", args[0], err) + os.Exit(1) return } cmd.Println("Success!") From 03b1e54b55abd57960daa4858fbab5106de7a15f Mon Sep 17 00:00:00 2001 From: Boyang Lyu Date: Fri, 8 Nov 2024 14:31:20 +0800 Subject: [PATCH 2/3] fixed the bug mention in issue 8762 Signed-off-by: Boyang Lyu --- tools/pd-ctl/pdctl/command/store_command.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tools/pd-ctl/pdctl/command/store_command.go b/tools/pd-ctl/pdctl/command/store_command.go index 48aeae253da..24c51319d69 100644 --- a/tools/pd-ctl/pdctl/command/store_command.go +++ b/tools/pd-ctl/pdctl/command/store_command.go @@ -19,7 +19,6 @@ import ( "encoding/json" "fmt" "net/http" - "os" "path" "strconv" "strings" @@ -64,7 +63,7 @@ func NewDeleteStoreByAddrCommand() *cobra.Command { d := &cobra.Command{ Use: "addr
", Short: "delete store by its address", - Run: deleteStoreCommandByAddrFunc, + RunE: deleteStoreCommandByAddrFunc, } return d } @@ -379,21 +378,19 @@ func deleteStoreCommandFunc(cmd *cobra.Command, args []string) { cmd.Println("Success!") } -func deleteStoreCommandByAddrFunc(cmd *cobra.Command, args []string) { +func deleteStoreCommandByAddrFunc(cmd *cobra.Command, args []string) error { id := getStoreID(cmd, args, false) if id == -1 { - os.Exit(1) - return + return fmt.Errorf("Store not find.") } // delete store by its ID prefix := fmt.Sprintf(storePrefix, id) _, err := doRequest(cmd, prefix, http.MethodDelete, http.Header{}) if err != nil { - cmd.Printf("Failed to delete store %s: %s\n", args[0], err) - os.Exit(1) - return + return fmt.Errorf("Failed to delete store.") } cmd.Println("Success!") + return nil } func cancelDeleteStoreCommandFunc(cmd *cobra.Command, args []string) { From f7299cd31cdbb44955e279ac1966dd64382f0515 Mon Sep 17 00:00:00 2001 From: Boyang Lyu Date: Fri, 8 Nov 2024 14:43:53 +0800 Subject: [PATCH 3/3] fixed error string style Signed-off-by: Boyang Lyu --- tools/pd-ctl/pdctl/command/store_command.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/pd-ctl/pdctl/command/store_command.go b/tools/pd-ctl/pdctl/command/store_command.go index 24c51319d69..b95af582c57 100644 --- a/tools/pd-ctl/pdctl/command/store_command.go +++ b/tools/pd-ctl/pdctl/command/store_command.go @@ -381,13 +381,13 @@ func deleteStoreCommandFunc(cmd *cobra.Command, args []string) { func deleteStoreCommandByAddrFunc(cmd *cobra.Command, args []string) error { id := getStoreID(cmd, args, false) if id == -1 { - return fmt.Errorf("Store not find.") + return fmt.Errorf("store not find") } // delete store by its ID prefix := fmt.Sprintf(storePrefix, id) _, err := doRequest(cmd, prefix, http.MethodDelete, http.Header{}) if err != nil { - return fmt.Errorf("Failed to delete store.") + return fmt.Errorf("failed to delete store") } cmd.Println("Success!") return nil