lorenzodonini / ocpp-go

Open Charge Point Protocol implementation in Go
MIT License
262 stars 125 forks source link

Fix nil stateHandler in ocppj.NewServer() #58

Closed michaelbeaumont closed 3 years ago

michaelbeaumont commented 3 years ago

At the moment calling ocppj.NewServer(ws.NewServer(), nil, nil) throws:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x8f3777]

goroutine 57 [running]:
github.com/lorenzodonini/ocpp-go/ocppj.(*Endpoint).ParseMessage(0xc0002b8a10, 0xc000136a00, 0x3, 0x4, 0x3, 0x4, 0x26)
        /home/mike/projects/grid-x/client/vendor/github.com/lorenzodonini/ocpp-go/ocppj/ocppj.go:333 +0xc77

on use, because stateHandler isn't initialized before being passed to Endpoint{}

michaelbeaumont commented 3 years ago

I suspect the coverage decrease is a fluke?

lorenzodonini commented 3 years ago

I suspect the coverage decrease is a fluke?

Yes, never mind point decimal coverage changes. Coverall says 3 lines are not covered anymore, but I need to implement some more tests for error checking anyways.

Good catch, my refactoring definitely needs some more testing (also the reason why I haven't published it in a release yet).