socketcluster-client-go icon indicating copy to clipboard operation
socketcluster-client-go copied to clipboard

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

Open stevenaldinger opened this issue 4 years ago • 5 comments

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/[email protected]/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/[email protected]/scclient/client.go:65 +0x188
github.com/sacOO7/gowebsocket.(*Socket).Connect.func4(0xc000108020)
	/go/pkg/mod/github.com/sac!o!o7/[email protected]/gowebsocket.go:154 +0x264
created by github.com/sacOO7/gowebsocket.(*Socket).Connect
	/go/pkg/mod/github.com/sac!o!o7/[email protected]/gowebsocket.go:133 +0x50c

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

stevenaldinger avatar Mar 06 '21 22:03 stevenaldinger

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

stevenaldinger avatar Mar 07 '21 02:03 stevenaldinger

@stevenaldinger: how do you fix this?

gobliggg avatar Aug 08 '21 09:08 gobliggg

@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
	}

stevenaldinger avatar Aug 08 '21 20:08 stevenaldinger

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

happilymarrieddad avatar Sep 21 '23 22:09 happilymarrieddad

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

happilymarrieddad avatar Sep 22 '23 15:09 happilymarrieddad