Skip to content

Commit

Permalink
debug call
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Sep 27, 2024
1 parent e19ede6 commit d83b7bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions rpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,11 @@ func (h *handler) handleSubscribe(cp *callProc, msg *jsonrpcMessage) *jsonrpcMes

// runMethod runs the Go callback for an RPC method.
func (h *handler) runMethod(ctx context.Context, msg *jsonrpcMessage, callb *callback, args []reflect.Value) *jsonrpcMessage {
log.Info("runMethod", "Method", msg.Method, "msg", msg.String())
result, err := callb.call(ctx, msg.Method, args)
if err != nil {
log.Info("runMethod", "Method", msg.Method, "err", err)
log.Info("runMethod", "Method", msg.Method, "err.Error()", err.Error())
return msg.errorResponse(err)
}
return msg.response(result)
Expand Down
6 changes: 6 additions & 0 deletions rpc/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"strings"
"sync"
"time"

"github.com/XinFinOrg/XDPoSChain/log"
)

const (
Expand Down Expand Up @@ -92,6 +94,8 @@ func (msg *jsonrpcMessage) String() string {
}

func (msg *jsonrpcMessage) errorResponse(err error) *jsonrpcMessage {
log.Info("errorResponse", "err", err)
log.Info("errorResponse", "err.Error()", err.Error())
resp := errorMessage(err)
resp.ID = msg.ID
return resp
Expand All @@ -107,6 +111,8 @@ func (msg *jsonrpcMessage) response(result interface{}) *jsonrpcMessage {
}

func errorMessage(err error) *jsonrpcMessage {
log.Info("errorMessage", "err", err)
log.Info("errorMessage", "err.Error()", err.Error())
msg := &jsonrpcMessage{Version: vsn, ID: null, Error: &jsonError{
Code: defaultErrorCode,
Message: err.Error(),
Expand Down
4 changes: 3 additions & 1 deletion rpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ func (c *callback) call(ctx context.Context, method string, args []reflect.Value
}
if c.errPos >= 0 && !results[c.errPos].IsNil() {
// Method has returned non-nil error value.
err := results[c.errPos].Interface().(error)
err, ok := results[c.errPos].Interface().(error)
log.Info("call", "method", method, "err", err, "ok", ok)
log.Info("call", "method", method, "err.Error()", err.Error())
return reflect.Value{}, err
}
return results[0].Interface(), nil
Expand Down

0 comments on commit d83b7bc

Please sign in to comment.