Skip to content

fix: safely skip emails to members with invalid addresses#2635

Open
mroderick wants to merge 1 commit into
masterfrom
feature/fix-mailer-crash-on-invalid-email
Open

fix: safely skip emails to members with invalid addresses#2635
mroderick wants to merge 1 commit into
masterfrom
feature/fix-mailer-crash-on-invalid-email

Conversation

@mroderick
Copy link
Copy Markdown
Collaborator

Problem

NoMethodError: undefined method '[]' for nil crashed WorkshopInvitationMailer#invite_coach (and other mailers) when a member's email was invalid. The root cause: EmailHeaderHelper#mail_args returned nil for invalid emails, and every mailer called mail(mail_args(...)) directly, passing nil into ActionMailer.

Rollbar: https://app.rollbar.com/a/codebar-production/fix/item/codebar-production/690#detail

Changes

  • Add EmailHeaderHelper::SkippedEmail null object with no-op delivery methods
  • Add mail_to_member helper that validates email before calling mail(), logs the skip, and returns SkippedEmail when invalid
  • Migrate all 8 mailers (27 methods) from mail(mail_args(...)) to mail_to_member(...)
  • Guard EmailDelivery#log_sent_email when mail() was never called (skips would otherwise trigger MissingTemplate)
  • Remove the now-unused mail_args method
  • Add skip-path tests for every mailer method (39 new tests)

Verification

bundle exec rspec spec/mailers/ spec/helpers/email_header_helper_spec.rb — 80 examples, 0 failures

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
@mroderick mroderick requested a review from olleolleolle June 5, 2026 18:41
@mroderick mroderick marked this pull request as ready for review June 5, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant