lorenzodonini / ocpp-go

Open Charge Point Protocol implementation in Go
MIT License
275 stars 126 forks source link

Chargepoint.Stop does not return an error and crashes if provider is not available #143

Open bhatanku1 opened 2 years ago

bhatanku1 commented 2 years ago

I am trying to connect to the Steve Backend Provider. There is a use case where I want to disconnect. For the same I am using the Chargepoint.Stop() method.

For some reason, if Steve is not available, this call crashes the client. Is there a way to handle it more gracefully in a way that I can catch the error and it does not crash the client.

Regards Ankur

lorenzodonini commented 2 years ago

Hey @bhatanku1,

I'm aware that invoking Stop on a client on which the Start method was never invoked before crashes the client. This is actually by design (the same way you cannot close a TCP connection if it was never opened in the first place).

In general, I wouldn't suggest invoking any methods on the client, as long as the Start method hasn't returned. It simply doesn't make sense to attempt any message exchange, if the initial connection wasn't established. That should be easy to check on your side.

If there's more upvotes, I can definitely prevent the crash with a nil check, but I thought it was intuitive as it is. Will definitely document this detail though.