From 4bf3756aa85cde4246efcf1554305c1c8408a27f Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Mon, 29 Feb 2016 15:41:52 -0800 Subject: [PATCH] clientv3: document error handling in README --- clientv3/README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/clientv3/README.md b/clientv3/README.md index f89d39346..6b9735d03 100644 --- a/clientv3/README.md +++ b/clientv3/README.md @@ -42,7 +42,27 @@ if err != nil { ## Error Handling -TODO +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). + +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 + } +} +``` ## Examples