From b43583c9542baab24e66326cadf589e7a4cee357 Mon Sep 17 00:00:00 2001 From: Andrew Mirsky Date: Mon, 26 May 2025 11:27:42 -0400 Subject: [PATCH] reapplying any remaining stack traces to logging messages that weren't already included in other updates --- amqtt/mqtt/protocol/handler.py | 10 +++++----- amqtt/plugins/manager.py | 4 ++-- amqtt/scripts/sub_script.py | 4 ++-- docs/references/mqttclient.rst | 4 ++-- samples/client_publish.py | 4 ++-- samples/client_publish_acl.py | 2 +- samples/client_subscribe.py | 4 ++-- samples/client_subscribe_acl.py | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/amqtt/mqtt/protocol/handler.py b/amqtt/mqtt/protocol/handler.py index d7877f4..7da6574 100644 --- a/amqtt/mqtt/protocol/handler.py +++ b/amqtt/mqtt/protocol/handler.py @@ -138,11 +138,11 @@ class ProtocolHandler: if self.writer is not None: await self.writer.close() except asyncio.CancelledError: - self.logger.debug("Writer close was cancelled.") - except TimeoutError as e: - self.logger.debug(f"Writer close operation timed out: {e}.") - except OSError as e: - self.logger.debug(f"Writer close failed due to I/O error: {e}") + self.logger.debug("Writer close was cancelled.", exc_info=True) + except TimeoutError: + self.logger.debug("Writer close operation timed out.", exc_info=True) + except OSError: + self.logger.debug("Writer close failed due to I/O error.", exc_info=True) def _stop_waiters(self) -> None: self.logger.debug(f"Stopping {len(self._puback_waiters)} puback waiters") diff --git a/amqtt/plugins/manager.py b/amqtt/plugins/manager.py index e3c4496..0167df3 100644 --- a/amqtt/plugins/manager.py +++ b/amqtt/plugins/manager.py @@ -86,8 +86,8 @@ class PluginManager: plugin_context.logger = self.logger.getChild(ep.name) obj = plugin(plugin_context) return Plugin(ep.name, ep, obj) - except ImportError as ie: - self.logger.warning(f"Plugin {ep!r} import failed: {ie}") + except ImportError: + self.logger.warning(f"Plugin {ep!r} import failed", exc_info=True) return None diff --git a/amqtt/scripts/sub_script.py b/amqtt/scripts/sub_script.py index adf0807..536eb96 100644 --- a/amqtt/scripts/sub_script.py +++ b/amqtt/scripts/sub_script.py @@ -106,8 +106,8 @@ async def do_sub(client: MQTTClient, arguments: dict[str, Any]) -> None: except KeyboardInterrupt: await client.disconnect() logger.info(f"{client.client_id} Disconnected from broker") - except ConnectError as ce: - logger.fatal(f"Connection to '{arguments['--url']}' failed: {ce!r}") + except ConnectError: + logger.fatal(f"Connection to '{arguments['--url']}' failed.", exc_info=True) except asyncio.CancelledError: logger.fatal("Publish canceled due to previous error") diff --git a/docs/references/mqttclient.rst b/docs/references/mqttclient.rst index d6ae90b..df26542 100644 --- a/docs/references/mqttclient.rst +++ b/docs/references/mqttclient.rst @@ -38,8 +38,8 @@ The example below shows how to write a simple MQTT client which subscribes a top print("%d: %s => %s" % (i, packet.variable_header.topic_name, str(packet.payload.data))) await C.unsubscribe(['$SYS/broker/uptime', '$SYS/broker/load/#']) await C.disconnect() - except ClientException as ce: - logger.error("Client exception: %s" % ce) + except ClientException: + logger.error("Client exception", exc_info=True) if __name__ == '__main__': formatter = "[%(asctime)s] %(name)s {%(filename)s:%(lineno)d} %(levelname)s - %(message)s" diff --git a/samples/client_publish.py b/samples/client_publish.py index 57bcf58..9b0f4f6 100644 --- a/samples/client_publish.py +++ b/samples/client_publish.py @@ -43,8 +43,8 @@ async def test_coro2() -> None: await C.publish("a/b", b"TEST MESSAGE WITH QOS_2", qos=0x02) logger.info("messages published") await C.disconnect() - except ConnectError as ce: - logger.exception(f"Connection failed: {ce}") + except ConnectError: + logger.exception(f"Connection failed", exc_info=True) asyncio.get_event_loop().stop() diff --git a/samples/client_publish_acl.py b/samples/client_publish_acl.py index 0a1cbb6..2ecf33e 100644 --- a/samples/client_publish_acl.py +++ b/samples/client_publish_acl.py @@ -27,7 +27,7 @@ async def test_coro() -> None: logger.info("messages published") await C.disconnect() except ConnectError as ce: - logger.exception(f"Connection failed: {ce}") + logger.exception("Connection failed") asyncio.get_event_loop().stop() diff --git a/samples/client_subscribe.py b/samples/client_subscribe.py index 0a29efb..3d175d6 100644 --- a/samples/client_subscribe.py +++ b/samples/client_subscribe.py @@ -30,8 +30,8 @@ async def uptime_coro() -> None: await C.unsubscribe(["$SYS/broker/uptime", "$SYS/broker/load/#"]) logger.info("UnSubscribed") await C.disconnect() - except ClientError as ce: - logger.exception(f"Client exception: {ce}") + except ClientError: + logger.exception("Client exception") if __name__ == "__main__": diff --git a/samples/client_subscribe_acl.py b/samples/client_subscribe_acl.py index aa69435..1810b6b 100644 --- a/samples/client_subscribe_acl.py +++ b/samples/client_subscribe_acl.py @@ -35,7 +35,7 @@ async def uptime_coro() -> None: logger.info("UnSubscribed") await C.disconnect() except ClientError as ce: - logger.exception(f"Client exception: {ce}") + logger.exception("Client exception") if __name__ == "__main__":