good morning!!!!

Skip to content
Commits on Source (2)
......@@ -18,7 +18,7 @@ package jrpc
import (
"context"
"encoding/json"
gojson "encoding/json"
"errors"
"fmt"
"net/url"
......@@ -26,7 +26,7 @@ import (
"sync/atomic"
"time"
jsoniter "github.com/json-iterator/go"
"github.com/goccy/go-json"
"tuxpa.in/a/zlog/log"
)
......@@ -288,7 +288,7 @@ func (c *Client) call(ctx context.Context, result any, msg *jsonrpcMessage) erro
case result == nil:
return nil
default:
return json.Unmarshal(resp.Result, &result)
return json.Unmarshal(resp.Result, result)
}
}
......@@ -434,7 +434,7 @@ func (c *Client) newMessageP(method string, paramIn any) (*jsonrpcMessage, error
msg := &jsonrpcMessage{ID: c.nextID(), Method: method}
if paramIn != nil { // prevent sending "params":null
var err error
if msg.Params, err = jsoniter.Marshal(paramIn); err != nil {
if msg.Params, err = json.Marshal(paramIn); err != nil {
return nil, err
}
}
......@@ -600,6 +600,9 @@ func (c *Client) read(codec ServerCodec) {
if _, ok := err.(*json.SyntaxError); ok {
codec.WriteJSON(context.Background(), errorMessage(&parseError{err.Error()}))
}
if _, ok := err.(*gojson.SyntaxError); ok {
codec.WriteJSON(context.Background(), errorMessage(&parseError{err.Error()}))
}
if err != nil {
c.readErr <- err
return
......
......@@ -36,7 +36,7 @@ import (
)
func init() {
zlog.SetGlobalLevel(zlog.FatalLevel)
zlog.SetGlobalLevel(zlog.ErrorLevel)
}
func TestClientRequest(t *testing.T) {
......
......@@ -2,11 +2,11 @@ package jrpc
import (
"context"
"encoding/json"
stdjson "encoding/json"
"io"
"sync"
"time"
"github.com/goccy/go-json"
)
// DeadlineConn is a subset of the methods of net.Conn which are sufficient for creating a jsonCodec
......@@ -66,7 +66,7 @@ func NewCodec(conn DeadlineConn) ServerCodec {
// TODO:
// for some reason other json decoders are incompatible with our test suite
// pretty sure its how we handle EOFs and stuff
dec := stdjson.NewDecoder(conn)
dec := json.NewDecoder(conn)
dec.UseNumber()
return NewFuncCodec(conn, encr, dec.Decode, func() error {
return nil
......
......@@ -103,14 +103,18 @@ func (e *callback) ServeRPC(w ResponseWriter, r *Request) {
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
log.Error().Str("method", r.Method).Interface("err", err).Hex("buf", buf).Msg("crashed")
log.Error().Str("method", r.Method).Interface("err", fmt.Sprintf("%s", err)).Stack().Msg("reflect handler crashed")
// errRes := errors.New("method handler crashed: " + fmt.Sprint(err))
w.Send(nil, fmt.Errorf("%s", err))
w.Send(nil, fmt.Errorf("recover: %s", err))
return
}
}()
// Run the callback.
results := e.fn.Call(fullargs)
if len(results) == 0 {
w.Send(nil, nil)
return
}
if e.errPos >= 0 && !results[e.errPos].IsNil() {
// Method has returned non-nil error value.
err := results[e.errPos].Interface().(error)
......
......@@ -6,7 +6,6 @@ import (
"net/http"
"sync/atomic"
"tuxpa.in/a/zlog/log"
mapset "github.com/deckarep/golang-set"
)
......@@ -98,7 +97,6 @@ func (s *Server) serveSingleRequest(ctx context.Context, codec ServerCodec) {
// subscriptions.
func (s *Server) Stop() {
if atomic.CompareAndSwapInt32(&s.run, 1, 0) {
log.Debug().Msg("RPC server shutting down")
s.codecs.Each(func(c any) bool {
c.(ServerCodec).Close()
return true
......
// This test checks that an error is written for invalid JSON requests.
--> 'f
<-- {"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"invalid character '\\'' looking for beginning of value"}}
<-- {"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"json: invalid character \n as bool(false)"}}