autopaho publisher example: panic due to nil pointer
bronger opened this issue · comments
I get a nil pointer dereference in the autopaho publisher example because pr
can be nil even if err is also nil.
Yep - if you publish with Qos=0
then there will be no response, so pr
will be nil. That should be the only time that this happens (any other occurrence would be a bug). I'm going to assume that you are using 0 QOS.
I can think of two possible fixes:
- Check cfg.qos >0 in the example.
- Change
Publish
such that a pointer to a default (empty)PublishResponse
is returned.
I'm tempted by option 2 because I think it would be easy to write some code using QOS1/2 and then change to QOS0 without considering that there is no longer a response to check.
Thoughts?
If a zero value for PublishResponse
is semantically senseful for QoS==0 (sorry but I’m not really competent to say that), go for option 2.