Skip to content

Commit

Permalink
Merge pull request #1771 from Odianosen25/mqtt-decode-error
Browse files Browse the repository at this point in the history
Help with better debugging of mqtt decode error
  • Loading branch information
acockburn committed Apr 24, 2023
2 parents 4eeafe4 + a75effd commit f3a1229
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions appdaemon/plugins/mqtt/mqttplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ def mqtt_on_message(self, client, userdata, msg):

if topic not in self.mqtt_binary_topics and wildcard not in self.mqtt_binary_topics:
# the binary data is not required
payload = payload.decode()
try:
payload = payload.decode()
except UnicodeDecodeError as u:
self.logger.info(f"Unable to decode MQTT message from topic {topic}, ignoring message")
self.logger.error(f"Unable to decode MQTT message from topic {topic}, with error: {u}")
return

data.update({"wildcard": wildcard, "payload": payload})

Expand All @@ -281,18 +286,10 @@ def mqtt_on_message(self, client, userdata, msg):
}

self.loop.create_task(self.send_ad_event(event_data))

except UnicodeDecodeError:
self.logger.info("Unable to decode MQTT message")
self.logger.error(
"Unable to decode MQTT message, with Traceback: %s",
traceback.format_exc(),
)
except Exception as e:
self.logger.critical("There was an error while processing an MQTT message: {} {}".format(type(e), e))
self.logger.critical(f"There was an error while processing MQTT message: {type(e)} {e}")
self.logger.error(
"There was an error while processing an MQTT message, with Traceback: %s",
traceback.format_exc(),
f"There was an error while processing MQTT message, with Traceback: {traceback.format_exc()}"
)

def mqtt_subscribe(self, topic, qos):
Expand Down

0 comments on commit f3a1229

Please sign in to comment.