diff --git a/server/socket.go b/server/socket.go index 8b5a9c128..c30dcd655 100644 --- a/server/socket.go +++ b/server/socket.go @@ -126,7 +126,7 @@ func (h *SocketHub) welcome(subscriber *socketSubscriber, params []util.Param) { if sharder, ok := (p.Val).(util.Sharder); ok { sharders[k] = sharder } else { - msg[k] = json.RawMessage(socketEncode(p.Val)) + msg[k] = json.RawMessage(socketEncode(k, p.Val)) } } @@ -138,7 +138,7 @@ func (h *SocketHub) welcome(subscriber *socketSubscriber, params []util.Param) { for k, sharder := range sharders { for key, val := range sharder.AllShards() { if b, err := json.Marshal(map[string]json.RawMessage{ - k + "." + key: json.RawMessage(socketEncode(val)), + k + "." + key: json.RawMessage(socketEncode(k, val)), }); err == nil { subscriber.send <- b } @@ -164,10 +164,10 @@ func (h *SocketHub) broadcast(p util.Param) { // Sharder splits data into chunks if sp, ok := (p.Val).(util.Sharder); ok { for key, val := range sp.ModifiedShards() { - msg[k+"."+key] = json.RawMessage(socketEncode(val)) + msg[k+"."+key] = json.RawMessage(socketEncode(k, val)) } } else { - msg[k] = json.RawMessage(socketEncode(p.Val)) + msg[k] = json.RawMessage(socketEncode(k, p.Val)) } b, _ := json.Marshal(msg) diff --git a/server/socket_helper.go b/server/socket_helper.go index f59be6837..cd5e66cdd 100644 --- a/server/socket_helper.go +++ b/server/socket_helper.go @@ -30,7 +30,7 @@ func encodeSliceAsString(v any) (string, error) { return fmt.Sprintf("[%s]", strings.Join(res, ",")), nil } -func socketEncode(pval any) string { +func socketEncode(key string, pval any) string { var ( val string err error @@ -44,7 +44,8 @@ func socketEncode(pval any) string { } if err != nil { - panic(err) + log.ERROR.Printf("invalid data for key %s in socket encode: %v", key, pval) + return "null" } return val