Browse Source

etcdctl: print out better error information

Xiang Li 10 năm trước cách đây
mục cha
commit
7e04a79fb4
2 tập tin đã thay đổi với 6 bổ sung1 xóa
  1. 5 0
      etcdctl/command/error.go
  2. 1 1
      etcdctl/command/util.go

+ 5 - 0
etcdctl/command/error.go

@@ -17,6 +17,8 @@ package command
 import (
 	"fmt"
 	"os"
+
+	"github.com/coreos/etcd/client"
 )
 
 const (
@@ -29,5 +31,8 @@ const (
 
 func handleError(code int, err error) {
 	fmt.Fprintln(os.Stderr, "Error: ", err)
+	if cerr, ok := err.(*client.ClusterError); ok {
+		fmt.Fprintln(os.Stderr, cerr.Detail())
+	}
 	os.Exit(code)
 }

+ 1 - 1
etcdctl/command/util.go

@@ -215,7 +215,7 @@ func mustNewClient(c *cli.Context) client.Client {
 		err := hc.Sync(ctx)
 		cancel()
 		if err != nil {
-			fmt.Fprintln(os.Stderr, err.Error())
+			handleError(ExitServerError, err)
 			os.Exit(1)
 		}
 	}