mx_check() function doesn't log exceptions #3
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: karolyi/py3-validate-email#3
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The
mx_check()
function insidemx_check.py
catches allValueError
exceptions and it just returnsFalse
with no additional information on what the error is.I was having some trouble validating a hotmail.co.uk email address (the address exists and is valid) and as I was tracing the error, I realised the above.
Is there a way to add logging to the
mx_check()
function when handling theValueError
so there is visibility on the actual errors which caused the validation to fail?Hey,
thanks for the report. I could let the
ValueError
bubble up in the stack, but that would kinda beat the purpose of returning a true/false/none which would simply tell the developer if the address is usable or not.Can you tell me what the cause for the
ValueError
was in your case?Looking more into it there wasn't a
ValueError
after all. It was an inconclusive result, so function returnedNone
. Anyways, my case is resolved, I think for now.I totally agree the function should return true/false/none. However, I was thinking something like the below:
Then, it's up to each developer to stream these log messages to stderr - especially, if someone is using the module inside a server environment. In this case, they can choose which loggers to collect messages from.
I think this is a very good idea, and I would go even further and say that any reason why an email address is refused should be logged. Also, I'd log with
logger.info
because the traceback of the exception is not interesting, and a log level ofERROR
does not fit an event that occurs in regular use of the library.Thinking this further, I'd like to propose that:
EmailValidationError
.check_email()
does all the checks, letting the exceptions through to the caller so the caller can decide what to do with that information, like even displaying a detailled error message in the user interface.validate_email()
just callscheck_email()
, catches allEmailValidationError
exceptions, logs them tologger.info
and returnsFalse
instead.What do you think? If you want, I could look into preparing a pull request for that.
Sounds good to me, but I'd call the function something else that's more indicative of letting exceptions through.
Prepare a PR and I'll look into it. Also make sure you have tests for the new functionality.
See #8.
Closed in #8.