Skip to content

Commit d7f9f83

Browse files
xiang90Michal Witkowski
authored and
Michal Witkowski
committed
discovery: print out detailed cluster error
1 parent 8ce8380 commit d7f9f83

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

client/cluster_error.go

+10
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@
1414

1515
package client
1616

17+
import "fmt"
18+
1719
type ClusterError struct {
1820
Errors []error
1921
}
2022

2123
func (ce *ClusterError) Error() string {
2224
return ErrClusterUnavailable.Error()
2325
}
26+
27+
func (ce *ClusterError) Detail() string {
28+
s := ""
29+
for i, e := range ce.Errors {
30+
s += fmt.Sprintf("error #%d: %s\n", i, e)
31+
}
32+
return s
33+
}

discovery/discovery.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ func (d *discovery) checkCluster() ([]*client.Node, int, uint64, error) {
221221
if err == client.ErrInvalidJSON {
222222
return nil, 0, 0, ErrBadDiscoveryEndpoint
223223
}
224-
if _, ok := err.(*client.ClusterError); ok {
224+
if ce, ok := err.(*client.ClusterError); ok {
225+
plog.Error(ce.Detail())
225226
return d.checkClusterRetry()
226227
}
227228
return nil, 0, 0, err
@@ -235,7 +236,8 @@ func (d *discovery) checkCluster() ([]*client.Node, int, uint64, error) {
235236
resp, err = d.c.Get(ctx, d.cluster, nil)
236237
cancel()
237238
if err != nil {
238-
if _, ok := err.(*client.ClusterError); ok {
239+
if ce, ok := err.(*client.ClusterError); ok {
240+
plog.Error(ce.Detail())
239241
return d.checkClusterRetry()
240242
}
241243
return nil, 0, 0, err
@@ -266,7 +268,7 @@ func (d *discovery) checkCluster() ([]*client.Node, int, uint64, error) {
266268
func (d *discovery) logAndBackoffForRetry(step string) {
267269
d.retries++
268270
retryTime := time.Second * (0x1 << d.retries)
269-
plog.Infof("%s: connection to %s timed out, retrying in %s", step, d.url, retryTime)
271+
plog.Infof("%s: error connecting to %s, retrying in %s", step, d.url, retryTime)
270272
d.clock.Sleep(retryTime)
271273
}
272274

@@ -311,7 +313,8 @@ func (d *discovery) waitNodes(nodes []*client.Node, size int, index uint64) ([]*
311313
plog.Noticef("found %d peer(s), waiting for %d more", len(all), size-len(all))
312314
resp, err := w.Next(context.Background())
313315
if err != nil {
314-
if _, ok := err.(*client.ClusterError); ok {
316+
if ce, ok := err.(*client.ClusterError); ok {
317+
plog.Error(ce.Detail())
315318
return d.waitNodesRetry()
316319
}
317320
return nil, err

0 commit comments

Comments
 (0)