41
41
42
42
"""
43
43
import json
44
- from adafruit_minimqtt import MMQTTException
44
+ from adafruit_minimqtt . adafruit_minimqtt import MMQTTException
45
45
46
46
__version__ = "0.0.0-auto.0"
47
47
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_AWS_IOT.git"
@@ -77,11 +77,11 @@ def __init__(self, mmqttclient, keep_alive=30):
77
77
assert (
78
78
self .cid [0 ] != "$"
79
79
), "Client ID can not start with restricted client ID prefix $."
80
- except :
80
+ except Exception as ex :
81
81
raise TypeError (
82
82
"You must provide MiniMQTT with your AWS IoT Device's Identifier \
83
83
as the Client ID."
84
- )
84
+ ) from ex
85
85
# Shadow-interaction topic
86
86
self .shadow_topic = "$aws/things/{}/shadow" .format (self .cid )
87
87
# keep_alive timer must be between 30 <= keep alive interval <= 1200 seconds
@@ -125,7 +125,7 @@ def disconnect(self):
125
125
try :
126
126
self .client .disconnect ()
127
127
except MMQTTException as error :
128
- raise AWS_IOT_ERROR ("Error disconnecting with AWS IoT: " , error )
128
+ raise AWS_IOT_ERROR ("Error disconnecting with AWS IoT: " , error ) from error
129
129
self .connected_to_aws = False
130
130
# Reset user-defined callback methods to None
131
131
self .on_connect = None
@@ -142,7 +142,7 @@ def reconnect(self):
142
142
try :
143
143
self .client .reconnect ()
144
144
except MMQTTException as error :
145
- raise AWS_IOT_ERROR ("Error re-connecting to AWS IoT:" , error )
145
+ raise AWS_IOT_ERROR ("Error re-connecting to AWS IoT:" , error ) from error
146
146
147
147
def connect (self , clean_session = True ):
148
148
"""Connects to Amazon AWS IoT MQTT Broker with Client ID.
@@ -152,7 +152,7 @@ def connect(self, clean_session=True):
152
152
try :
153
153
self .client .connect (clean_session )
154
154
except MMQTTException as error :
155
- raise AWS_IOT_ERROR ("Error connecting to AWS IoT: " , error )
155
+ raise AWS_IOT_ERROR ("Error connecting to AWS IoT: " , error ) from error
156
156
self .connected_to_aws = True
157
157
158
158
# MiniMQTT Callback Handlers
0 commit comments