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

Fix exception chaining for non-built-in exceptions #9266

Merged
merged 3 commits into from
May 21, 2024

Conversation

jepler
Copy link
Member

@jepler jepler commented May 21, 2024

The cause was that setting the __cause__ property on an exception didn't set the built in exception object's cause property, so it's necessary to fetch the property from the actual object when needed.

@justmobilize
Copy link

Tested on a UM FeatherS3:

This code will fail, since the MQTT server isn't connecting vis SSL, but on a SSL port:

import adafruit_connection_manager
import wifi
esp = wifi.radio
pool = adafruit_connection_manager.get_radio_socketpool(esp)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
import adafruit_minimqtt.adafruit_minimqtt as MQTT
mqtt_client = MQTT.MQTT(
     broker="io.adafruit.com",
     username="ADAFRUIT_AIO_USERNAME",
     password="ADAFRUIT_AIO_KEY",
     port=8883,
     socket_timeout=1,
     recv_timeout=2,
     socket_pool=pool,
     ssl_context=ssl_context,
     is_ssl=False,
)
mqtt_client.connect()

Result:

Traceback (most recent call last):
  File "adafruit_minimqtt/adafruit_minimqtt.py", line 429, in connect
  File "adafruit_minimqtt/adafruit_minimqtt.py", line 567, in _connect
Exception: ('No data received from broker for 2 seconds.', None)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_minimqtt/adafruit_minimqtt.py", line 458, in connect
MMQTTException: ('Repeated connect failures', None)

@dhalbert
Copy link
Collaborator

@justmobilize so are you saying it works for you? Not sure :)

@justmobilize
Copy link

@dhalbert , yes I now see both exceptions. This works perfectly

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the quick fix!

@dhalbert dhalbert merged commit 1a3c471 into adafruit:9.0.x May 21, 2024
495 checks passed
@dhalbert dhalbert mentioned this pull request May 22, 2024
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

Successfully merging this pull request may close these issues.

None yet

3 participants