mosquito / aiormq

Pure python AMQP 0.9.1 asynchronous client library
Other
276 stars 58 forks source link

Exception log method used outside exception handler for unexpected connection close #200

Open raqbit opened 3 months ago

raqbit commented 3 months ago

When a connection is unexpectedly closed, aiormq logs this with the log.exception function (link), breaking parts of the structlog logging library.

The structlog ExceptionDictTransformer exception transformer expects this function to only get called from an exception handler. When called outside an exception handler, it raises an exception itself when it is passed the results of sys.exc_info() ((None, None, None)), as it tries to access __name__ of the exc_type.

While I think it is a bug in the structlog library that this leads to an exception during logging (issue) I think it would be nice to change the log.exception into log.error to avoid triggering this bug or potentially other bugs in log formatters that expect exception to only be used while handling an exception.