sacOO7 / socketcluster-client-go

GO client for socketcluster
https://socketcluster.io/
Apache License 2.0
55 stars 20 forks source link

panic: interface conversion: interface {} is nil, not map[string]interface {} #14

Open stevenaldinger opened 3 years ago

stevenaldinger commented 3 years ago

This happens a few seconds after successfully connecting to the server when I run the code in the README. No message is being published and there's nothing but a fmt.Println in my startCode function.

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 37 [running]:
github.com/sacOO7/socketcluster-client-go/scclient/parser.GetMessageDetails(0x0, 0x0, 0x0, 0x6d7d40, 0xc000058ef0, 0x7cc220, 0xc00000e480, 0x9870b4, 0x9870b4, 0xf4c)
    /go/pkg/mod/github.com/sac!o!o7/socketcluster-client-go@v1.0.0/scclient/parser/parser.go:28 +0x40e
github.com/sacOO7/socketcluster-client-go/scclient.(*Client).registerCallbacks.func3(0x0, 0x0, 0xc0001ac000, 0xc000106080, 0x76b0e9, 0x26, 0x100, 0x0, 0x0, 0x0, ...)
    /go/pkg/mod/github.com/sac!o!o7/socketcluster-client-go@v1.0.0/scclient/client.go:65 +0x188
github.com/sacOO7/gowebsocket.(*Socket).Connect.func4(0xc000108020)
    /go/pkg/mod/github.com/sac!o!o7/gowebsocket@v0.0.0-20210105141656-425813c1c643/gowebsocket.go:154 +0x264
created by github.com/sacOO7/gowebsocket.(*Socket).Connect
    /go/pkg/mod/github.com/sac!o!o7/gowebsocket@v0.0.0-20210105141656-425813c1c643/gowebsocket.go:133 +0x50c

Is this client maintained/expected to work with the latest socketcluster server release?

stevenaldinger commented 3 years ago

this fixes the panic: https://github.com/sacOO7/socketcluster-client-go/pull/15

gobliggg commented 2 years ago

@stevenaldinger: how do you fix this?

stevenaldinger commented 2 years ago

@gobliggg in scclient/parser/parser.go line 28: https://github.com/sacOO7/socketcluster-client-go/blob/master/scclient/parser/parser.go#L28

replace:

    itemsMap := message.(map[string]interface{})

with a check that the conversion is successful. keep in mind there's likely some deeper rooted issue that the conversion failed to begin with, but its still important to be catching errors like this. I'm not sure what appropriate error handling should be happening here, this just completely ignores the error instead of letting it panic:

    itemsMap, ok := message.(map[string]interface{})
    if !ok {
        return
    }
happilymarrieddad commented 10 months ago

https://github.com/sacOO7/socketcluster-client-go/pull/16

happilymarrieddad commented 9 months ago

Appears to be fixed in github.com/sacOO7/socketcluster-client-go v1.0.1-0.20230922063628-e06423a4ac46