Skip to content

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

Merged
olleolleolle merged 1 commit into
masterfrom
feature/fix-mailer-crash-on-invalid-email
Jun 6, 2026
Merged

fix: safely skip emails to members with invalid addresses#2635
olleolleolle merged 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
Copy link
Copy Markdown
Collaborator

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes an issue in a fun way. Thanks!

@olleolleolle olleolleolle merged commit 6a3b34a into master Jun 6, 2026
16 checks passed
@olleolleolle olleolleolle deleted the feature/fix-mailer-crash-on-invalid-email branch June 6, 2026 11:00
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.

2 participants