|
|
@@ -52,21 +52,22 @@ For more detail, please read [Go vendor design](https://golang.org/s/go15vendor)
|
|
|
etcd client returns 2 types of errors:
|
|
|
|
|
|
1. context error: canceled or deadline exceeded.
|
|
|
-2. gRPC error: see [v3rpc/error](https://github.com/coreos/etcd/blob/master/etcdserver/api/v3rpc/error.go).
|
|
|
+2. gRPC error: see [api/v3rpc/rpctypes](https://godoc.org/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes).
|
|
|
|
|
|
Here is the example code to handle client errors:
|
|
|
|
|
|
```go
|
|
|
resp, err := kvc.Put(ctx, "", "")
|
|
|
if err != nil {
|
|
|
- if err == context.Canceled {
|
|
|
- // ctx is canceled by another routine
|
|
|
- } else if err == context.DeadlineExceeded {
|
|
|
- // ctx is attached with a deadline and it exceeded
|
|
|
- } else if verr, ok := err.(*v3rpc.ErrEmptyKey); ok {
|
|
|
- // process (verr.Errors)
|
|
|
- } else {
|
|
|
- // bad cluster endpoints, which are not etcd servers
|
|
|
+ switch err {
|
|
|
+ case context.Canceled:
|
|
|
+ log.Fatalf("ctx is canceled by another routine: %v", err)
|
|
|
+ case context.DeadlineExceeded:
|
|
|
+ log.Fatalf("ctx is attached with a deadline is exceeded: %v", err)
|
|
|
+ case rpctypes.ErrEmptyKey:
|
|
|
+ log.Fatalf("client-side error: %v", err)
|
|
|
+ default:
|
|
|
+ log.Fatalf("bad cluster endpoints, which are not etcd servers: %v", err)
|
|
|
}
|
|
|
}
|
|
|
```
|