mail icon indicating copy to clipboard operation
mail copied to clipboard

NameError: undefined local variable or method `to_ary' for #<Mail::Part:0x0000563a8b823950>

Open ujinius opened this issue 3 years ago • 0 comments

I'm getting periodically this issue in logs, but it is not reproducing in 100%:

NameError: undefined local variable or method `to_ary' for #<Mail::Part:0x0000563a8b823950>
    vendor/ruby/2.6.0/gems/mail-2.7.1/lib/mail/message.rb:1396:in `method_missing'
    /usr/local/lib/ruby/2.6.0/delegate.rb:349:in `flatten'
    /usr/local/lib/ruby/2.6.0/delegate.rb:349:in `block in delegating_block'
    vendor/ruby/2.6.0/gems/mail-2.7.1/lib/mail/message.rb:1945:in `all_parts'
    vendor/ruby/2.6.0/gems/mail-2.7.1/lib/mail/message.rb:1945:in `block in all_parts'
    vendor/ruby/2.6.0/gems/mail-2.7.1/lib/mail/parts_list.rb:31:in `block in collect'
    /usr/local/lib/ruby/2.6.0/delegate.rb:349:in `each'
    /usr/local/lib/ruby/2.6.0/delegate.rb:349:in `block in delegating_block'
    vendor/ruby/2.6.0/gems/mail-2.7.1/lib/mail/parts_list.rb:31:in `collect'
    vendor/ruby/2.6.0/gems/mail-2.7.1/lib/mail/message.rb:1945:in `all_parts'
    vendor/ruby/2.6.0/gems/mail-2.7.1/lib/mail/message.rb:1949:in `find_first_mime_type'
    vendor/ruby/2.6.0/gems/mail-2.7.1/lib/mail/message.rb:1670:in `html_part'
    vendor/ruby/2.6.0/gems/roadie-rails-2.2.0/lib/roadie/rails/mail_inliner.rb:16:in `execute'
    vendor/ruby/2.6.0/gems/roadie-rails-2.2.0/lib/roadie/rails/inline_on_delivery.rb:25:in `inline_styles'
    vendor/ruby/2.6.0/gems/roadie-rails-2.2.0/lib/roadie/rails/inline_on_delivery.rb:12:in `deliver'
    vendor/ruby/2.6.0/gems/actionmailer-5.2.6/lib/action_mailer/message_delivery.rb:114:in `block in deliver_now'
    vendor/ruby/2.6.0/gems/actionmailer-5.2.6/lib/action_mailer/rescuable.rb:17:in `handle_exceptions'
    vendor/ruby/2.6.0/gems/actionmailer-5.2.6/lib/action_mailer/message_delivery.rb:113:in `deliver_now'
    .....
    ....
    ..

And for now I fixed this only by monkey-patching:

module Mail
  class Part < Message
    def respond_to?(method_name, include_private = false)
      return false if method_name == :to_ary

      super
    end

    def method_missing(name, *args, &block)
      raise NoMethodError if name == :to_ary

      super
    end
  end
end

is there any other way to fix this?

Thank you

ujinius avatar Jun 30 '21 11:06 ujinius