From b9a1c4945de373d41f16957b46692b0ca9ce0d64 Mon Sep 17 00:00:00 2001 From: Chris Buckland Date: Thu, 1 Feb 2024 20:36:37 +0000 Subject: [PATCH 1/2] Log error data where available --- util/rpcclient/rpcclient.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/util/rpcclient/rpcclient.go b/util/rpcclient/rpcclient.go index dee6e9252a..d88e6dfc36 100644 --- a/util/rpcclient/rpcclient.go +++ b/util/rpcclient/rpcclient.go @@ -155,13 +155,25 @@ func (c *RpcClient) CallContext(ctx_in context.Context, result interface{}, meth ctx, cancelCtx = context.WithCancel(ctx_in) } err = c.client.CallContext(ctx, result, method, args...) + cancelCtx() logger := log.Trace limit := int(c.config().ArgLogLimit) if err != nil && err.Error() != "already known" { logger = log.Info } - logger("rpc response", "method", method, "logId", logId, "err", err, "result", limitedMarshal{limit, result}, "attempt", i, "args", limitedArgumentsMarshal{limit, args}) + logEntry := []interface{}{ + "method", method, + "logId", logId, + "err", err, + "result", limitedMarshal{limit, result}, + "attempt", i, + "args", limitedArgumentsMarshal{limit, args}, + } + if da, ok := err.(rpc.DataError); ok { + logEntry = append(logEntry, "errorData", limitedMarshal{limit, da.ErrorData()}) + } + logger("rpc response", logEntry...) if err == nil { return nil } From e8167fee6804ba612ed0721b39d42a6b858094ed Mon Sep 17 00:00:00 2001 From: Chris Buckland Date: Thu, 1 Feb 2024 20:58:31 +0000 Subject: [PATCH 2/2] Use lint reco for errors.as --- util/rpcclient/rpcclient.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util/rpcclient/rpcclient.go b/util/rpcclient/rpcclient.go index d88e6dfc36..dbc145d490 100644 --- a/util/rpcclient/rpcclient.go +++ b/util/rpcclient/rpcclient.go @@ -170,8 +170,9 @@ func (c *RpcClient) CallContext(ctx_in context.Context, result interface{}, meth "attempt", i, "args", limitedArgumentsMarshal{limit, args}, } - if da, ok := err.(rpc.DataError); ok { - logEntry = append(logEntry, "errorData", limitedMarshal{limit, da.ErrorData()}) + var dataErr rpc.DataError + if errors.As(err, &dataErr) { + logEntry = append(logEntry, "errorData", limitedMarshal{limit, dataErr.ErrorData()}) } logger("rpc response", logEntry...) if err == nil {