agronholm / mqttproto

Sans-IO MQTT v5 protocol implementation for Python
MIT License
10 stars 3 forks source link

Connection failure doesn't raise an exception #16

Open smurfix opened 2 weeks ago

smurfix commented 2 weeks ago

I'm running pytest against my server which happens to require a login.

As the connection didn't succeed I'd expect the async with AsyncMQTTClient() call to raise an appropriate exception instead of continuing.

-> async def _run_operation(self, operation: MQTTOperation[Any]) -> None:
(Pdb) b 481
Breakpoint 1 at /src/mqttproto/src/mqttproto/async_client.py:481
(Pdb) c

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB continue >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /src/mqttproto/src/mqttproto/async_client.py(481)_run_operation()
-> if operation.exception:
(Pdb) p operation.exception
None
(Pdb) p operation.response.reason_code
<ReasonCode.NOT_AUTHORIZED: 135>
(Pdb) c
………
    | Traceback (most recent call last):
    |   File "/src/mqttproto/tests/test_async_client.py", line 14, in test_publish_subscribe
    |     async with client.subscribe("test/+") as messages:
…
| mqttproto.MQTTProtocolError: cannot perform this operation in the DISCONNECTED state (must be in one of the following states: CONNECTED)
agronholm commented 1 week ago

My goal was to provide transparent handling of intermittent issues, but maybe I went too far in trying to hide problems from the user. What would you suggest?