Compare commits

..

2 Commits

Author SHA1 Message Date
Yax 0d144a683f
Merge pull request #22 from evidencebp/main
Pylint alerts corrections as part of an intervention experiment 21 (src\stacosys\service\mail.py broad-exception-caught)
1 week ago
evidencebp 25ed2f06e0 src\stacosys\service\mail.py broad-exception-caught
Catching Exception might hide unexpected exceptions, like those that might be raised due to future modification.
Therefore, it is recommended to narrow the exceptions.

The method send of the class Mailer catches Exception in line 57.
MIMEText does not raise exceptions (if not using attachments).
See
https://docs.python.org/3/library/email.mime.html

Most code is handled in an inner exception handling.
In order to catch exception from SMTP_SSL I used SMTPException
See
https://docs.python.org/3/library/smtplib.html
1 week ago

@ -3,7 +3,7 @@
import logging
from email.mime.text import MIMEText
from smtplib import SMTP_SSL, SMTPAuthenticationError
from smtplib import SMTP_SSL, SMTPAuthenticationError, SMTPException
logger = logging.getLogger(__name__)
@ -54,6 +54,6 @@ class Mailer:
server.send_message(msg)
return True
except Exception:
except SMTPException:
logger.error("Error sending email", exc_info=True)
return False

Loading…
Cancel
Save