improve logging on serialization error

This commit is contained in:
2021-10-06 21:11:43 +02:00
parent af8eb8c141
commit bfac62c2b7

View File

@@ -96,15 +96,14 @@ class QuarantineMilter(Milter.Base):
def msg_as_bytes(self): def msg_as_bytes(self):
try: try:
data = self.msg.as_bytes() data = self.msg.as_bytes()
except Exception: except Exception as e:
self.logger.warning( self.logger.warning(f"unable to serialize message as bytes: {e}")
"unable to serialize message as bytes, "
"try to serialize as str and encode")
try: try:
self.logger.warning("try to serialize as str and encode")
data = self.msg.as_string().encode("ascii", errors="replace") data = self.msg.as_string().encode("ascii", errors="replace")
except Exception as e: except Exception as e:
self.logger.exception( self.logger.error(
"unable to serialize message, giving up") f"unable to serialize message, giving up: {e}")
raise e raise e
return data return data