Skip to content

Commit

Permalink
make 'polling client watch failed' errors more detailed (#794)
Browse files Browse the repository at this point in the history
* make 'polling client watch failed' errors more detailed

fix #793

* fix loop in http client json marshal
  • Loading branch information
willscott committed Apr 14, 2021
1 parent ec4f8f9 commit 60b060c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions client/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ func (h *httpClient) String() string {
return fmt.Sprintf("HTTP(%q)", h.root)
}

// Implement textMarshaller
func (h *httpClient) MarshalText() ([]byte, error) {
return json.Marshal(h.String())
}

type httpInfoResponse struct {
chainInfo *chain.Info
err error
Expand Down Expand Up @@ -234,11 +239,6 @@ func (h *httpClient) FetchChainInfo(chainHash []byte) (*chain.Info, error) {
}
}

// Implement textMarshaller
func (h *httpClient) MarshalText() ([]byte, error) {
return json.Marshal(h)
}

type httpGetResponse struct {
result client.Result
err error
Expand Down
6 changes: 3 additions & 3 deletions client/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func PollingWatcher(ctx context.Context, c Client, chainInfo *chain.Info, l log.
r := c.RoundAt(time.Now())
val, err := c.Get(ctx, r)
if err != nil {
l.Error("polling_client", "failed to watch", "err", err)
l.Error("polling_client", "failed synchronous get", "from", c, "err", err)
close(ch)
return ch
}
Expand All @@ -36,7 +36,7 @@ func PollingWatcher(ctx context.Context, c Client, chainInfo *chain.Info, l log.
if err == nil {
ch <- r
} else {
l.Error("polling_client", "failed to watch", "err", err)
l.Error("polling_client", "failed first async get", "from", c, "err", err)
}

// Then tick each period.
Expand All @@ -49,7 +49,7 @@ func PollingWatcher(ctx context.Context, c Client, chainInfo *chain.Info, l log.
if err == nil {
ch <- r
} else {
l.Error("polling_client", "failed to watch", "err", err)
l.Error("polling_client", "failed subsequent watch poll", "from", c, "err", err)
}
// TODO: keep trying on errors?
case <-ctx.Done():
Expand Down

0 comments on commit 60b060c

Please sign in to comment.