4141
4242"""
4343import json
44- from adafruit_minimqtt import MMQTTException
44+ from adafruit_minimqtt . adafruit_minimqtt import MMQTTException
4545
4646__version__ = "0.0.0-auto.0"
4747__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_AWS_IOT.git"
@@ -77,11 +77,11 @@ def __init__(self, mmqttclient, keep_alive=30):
7777 assert (
7878 self .cid [0 ] != "$"
7979 ), "Client ID can not start with restricted client ID prefix $."
80- except :
80+ except Exception as ex :
8181 raise TypeError (
8282 "You must provide MiniMQTT with your AWS IoT Device's Identifier \
8383 as the Client ID."
84- )
84+ ) from ex
8585 # Shadow-interaction topic
8686 self .shadow_topic = "$aws/things/{}/shadow" .format (self .cid )
8787 # keep_alive timer must be between 30 <= keep alive interval <= 1200 seconds
@@ -125,7 +125,7 @@ def disconnect(self):
125125 try :
126126 self .client .disconnect ()
127127 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
129129 self .connected_to_aws = False
130130 # Reset user-defined callback methods to None
131131 self .on_connect = None
@@ -142,7 +142,7 @@ def reconnect(self):
142142 try :
143143 self .client .reconnect ()
144144 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
146146
147147 def connect (self , clean_session = True ):
148148 """Connects to Amazon AWS IoT MQTT Broker with Client ID.
@@ -152,7 +152,7 @@ def connect(self, clean_session=True):
152152 try :
153153 self .client .connect (clean_session )
154154 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
156156 self .connected_to_aws = True
157157
158158 # MiniMQTT Callback Handlers
0 commit comments