Skip to content

Commit

Permalink
Log error data where available
Browse files Browse the repository at this point in the history
  • Loading branch information
yahgwai committed Feb 1, 2024
1 parent f6dfe98 commit b9a1c49
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion util/rpcclient/rpcclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 173 in util/rpcclient/rpcclient.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)

Check failure on line 173 in util/rpcclient/rpcclient.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)

Check failure on line 173 in util/rpcclient/rpcclient.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)
logEntry = append(logEntry, "errorData", limitedMarshal{limit, da.ErrorData()})
}
logger("rpc response", logEntry...)
if err == nil {
return nil
}
Expand Down

0 comments on commit b9a1c49

Please sign in to comment.