fix: safely skip emails to members with invalid addresses#2635
Open
mroderick wants to merge 1 commit into
Open
fix: safely skip emails to members with invalid addresses#2635mroderick wants to merge 1 commit into
mroderick wants to merge 1 commit into
Conversation
Replace the dangerous mail(mail_args(...)) pattern, which returned nil for invalid emails and caused NoMethodError crashes in ActionMailer, with a new mail_to_member helper that returns a SkippedEmail null object. Changes: - Add EmailHeaderHelper::SkippedEmail with no-op delivery methods - Add mail_to_member that validates email before calling mail() - Migrate all 8 mailers to use mail_to_member - Guard EmailDelivery#log_sent_email when mail was skipped - Remove the now-unused mail_args method - Add skip-path tests for every mailer method Fixes: https://app.rollbar.com/a/codebar-production/fix/item/codebar-production/690#detail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
NoMethodError: undefined method '[]' for nilcrashedWorkshopInvitationMailer#invite_coach(and other mailers) when a member's email was invalid. The root cause:EmailHeaderHelper#mail_argsreturnednilfor invalid emails, and every mailer calledmail(mail_args(...))directly, passingnilinto ActionMailer.Rollbar: https://app.rollbar.com/a/codebar-production/fix/item/codebar-production/690#detail
Changes
EmailHeaderHelper::SkippedEmailnull object with no-op delivery methodsmail_to_memberhelper that validates email before callingmail(), logs the skip, and returnsSkippedEmailwhen invalidmail(mail_args(...))tomail_to_member(...)EmailDelivery#log_sent_emailwhenmail()was never called (skips would otherwise triggerMissingTemplate)mail_argsmethodVerification
bundle exec rspec spec/mailers/ spec/helpers/email_header_helper_spec.rb— 80 examples, 0 failures