Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TopicsQosLevelsNotMatch exception in MqttMsgSubscribe not being raised at user code level #5

Open
patrickgardella opened this issue Jun 14, 2016 · 1 comment

Comments

@patrickgardella
Copy link

I made a mistake in trying some of the demo code, in that I was subscribing to two queues, but only passing in a single QOS level.

            string clientId = Guid.NewGuid().ToString();
            client.Connect(clientId);

            string[] topic = { "sensor/temp", "sensor/humidity" };

            byte[] qosLevels = { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE };

This caused an exception to be thrown:

uPLibrary.Networking.M2Mqtt.Exceptions.MqttClientException was unhandled
Message: An unhandled exception of type 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttClientException' occurred in M2Mqtt.Net.dll

(I was using the NuGet 4.3.0 code for this.) I couldn't catch this exception and handle it, because the true exception does not make it to the user's level. Nor could I find out what the actual exception was.

When I compiled the m2mqtt code from GitHub, I debugged it and found that MqttMsgSubscribe.GetBytes() was throwing a TopicsQosLevelsNotMatch exception:

uPLibrary.Networking.M2Mqtt.Exceptions.MqttClientException occurred
  HResult=-2146233088
  Message=Exception of type 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttClientException' was thrown.
  Source=M2Mqtt.Net
  StackTrace:
       at uPLibrary.Networking.M2Mqtt.Messages.MqttMsgSubscribe.GetBytes(Byte protocolVersion) in C:\Users\Patrick Gardella\Documents\Visual Studio 2015\Projects\paho.mqtt.m2mqtt\M2Mqtt\Messages\MqttMsgSubscribe.cs:line 187
  InnerException: 

It is the MqttClient.Send() that ignores the throw exceptions: M2Mqtt.Net.dll!uPLibrary.Networking.M2Mqtt.MqttClient.Send(uPLibrary.Networking.M2Mqtt.Messages.MqttMsgBase msg) Line 1029

Clearly I can avoid this now that I know what was wrong, but it would be good to either log the exception or raise it to the user's level.

Thanks for all your great work on this!

Patrick+

@HakamFostok
Copy link

HakamFostok commented Oct 7, 2016

I am facing the same problem, and I was able to solve it, here is the solution which could help others
http://stackoverflow.com/questions/39917469/

BUT, I think this really should be considered in the MQTT library, and the library should check for this case and throw an appropriate exception with a helpful message to help the user knowing what is going wrong.
Throwing this general exception make the developer confused about what he/she did wrong.

josesimoes referenced this issue in nanoframework/nanoFramework.m2mqtt Jul 10, 2019
Update nanoFramework NuGets to final versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants