bradpauly / griddler-mailgun

Mailgun adapter for the griddler gem.
MIT License
17 stars 27 forks source link

NoMethodError - undefined method `split' for nil:NilClass #3

Closed wgro closed 10 years ago

wgro commented 10 years ago

Hi,

I've been banging my head against the wall trying to get griddler to work with mailgun.

With every test POST from mailgun to my app, I receive the following error:

Oops! The server said: NoMethodError at /email_processor ================================= > undefined method `split' for nil:NilClass griddler-mailgun (1.0.0) lib/griddler/mailgun/adapter.rb, line 43 ----------------------------------------------------------------- ``` ruby 38 to_emails.split(',').map(&:strip) 39 end 40 41 def cc_recipients 42 cc = param_or_header(:Cc) > 43 cc.split(',').map(&:strip) 44 end 45 46 def headers 47 @headers ||= extract_headers 48 end ``` App backtrace ------------- Full backtrace -------------- - griddler-mailgun (1.0.0) lib/griddler/mailgun/adapter.rb:43:in `cc_recipients' - griddler-mailgun (1.0.0) lib/griddler/mailgun/adapter.rb:16:in `normalize_params' - griddler-mailgun (1.0.0) lib/griddler/mailgun/adapter.rb:10:in `normalize_params' - /usr/local/Cellar/rbenv/0.4.0/versions/2.1.2/lib/ruby/gems/2.1.0/gems/griddler-1.0.0/app/controllers/griddler/emails_controller.rb:15:in `normalized_params' - /usr/local/Cellar/rbenv/0.4.0/versions/2.1.2/lib/ruby/gems/2.1.0/gems/griddler-1.0.0/app/controllers/griddler/emails_controller.rb:3:in `create' - actionpack (4.1.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action' - actionpack (4.1.0) lib/abstract_controller/base.rb:189:in `process_action' - actionpack (4.1.0) lib/action_controller/metal/rendering.rb:10:in `process_action' - actionpack (4.1.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action' - activesupport (4.1.0) lib/active_support/callbacks.rb:113:in `call' - activesupport (4.1.0) lib/active_support/callbacks.rb:229:in `block in halting' - activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `block in halting' - activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `block in halting' - activesupport (4.1.0) lib/active_support/callbacks.rb:86:in `run_callbacks' - actionpack (4.1.0) lib/abstract_controller/callbacks.rb:19:in `process_action' - actionpack (4.1.0) .....etc etc

I have :mailgun specified in the griddler.rb file, and the email_processor in the /lib directory. This was previously working using cloudmailin, so I'm not sure what's going on here.

My route is the default, mount_griddler.

Any advice? Pardon the noob-ish question here.

bradpauly commented 10 years ago

Sorry about that. It looks like this is related to the message header parsing bug. https://github.com/thoughtbot/griddler/issues/122

Is it possible for you to upgrate to 1.0, which was released today?

wgro commented 10 years ago

Thanks for getting back to me.

Yep, I'm using both 1.0 for both griddler and griddler-mailgun.

bradpauly commented 10 years ago

Thanks, I think I see where the problem is. If you have the params that mailgun is sending would you mind putting them in a gist for me to look at?

wgro commented 10 years ago

Sure thing.

Here's are the params: https://gist.github.com/wgro/905132a0cebdbec2e482

bradpauly commented 10 years ago

Great, thanks. I just pushed a fix. If you want to try it out now you can point to the git repo in your Gemfile with this:

gem "griddler-mailgun", git:"git://github.com/bradpauly/griddler-mailgun.git"

I'll be able to test in a live environment later today. Again, sorry about the bug!

wgro commented 10 years ago

No problem! Being new at this, I just assumed I had messed up something.

I'm still getting an error though, albeit a different one:

NoMethodError - undefined method `to_crlf' for #<ActiveSupport::HashWithIndifferentAccess:0x007f930a920348>:
  mail (2.5.4) lib/mail/header.rb:53:in `initialize'
  griddler (1.0.0) lib/griddler/email_parser.rb:43:in `extract_headers'
  griddler (1.0.0) lib/griddler/email.rb:51:in `extract_headers'
  griddler (1.0.0) lib/griddler/email.rb:21:in `initialize'
  /usr/local/Cellar/rbenv/0.4.0/versions/2.1.2/lib/ruby/gems/2.1.0/gems/griddler-1.0.0/app/controllers/griddler/emails_controller.rb:4:in `block in create'
  /usr/local/Cellar/rbenv/0.4.0/versions/2.1.2/lib/ruby/gems/2.1.0/gems/griddler-1.0.0/app/controllers/griddler/emails_controller.rb:3:in `create'
  actionpack (4.1.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.1.0) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.1.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.1.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.1.0) lib/active_support/callbacks.rb:113:in `call'
  activesupport (4.1.0) lib/active_support/callbacks.rb:229:in `block in halting'
  activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.0) lib/active_support/callbacks.rb:86:in `run_callbacks'
  actionpack (4.1.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.1.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.1.0) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.1.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.1.0) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.1.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.1.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.1.0) lib/abstract_controller/base.rb:136:in `process'
  actionview (4.1.0) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.1.0) lib/action_controller/metal.rb:195:in `dispatch'

and so on...

Let me know if I can be of any help!

bradpauly commented 10 years ago

@wgro so sorry for the trouble. I made a mistake by passing the headers to griddler as they are being used internally while they are expecting raw email headers. I've removed headers from normalized_params because they are optional for an adapter. I'll research re-composing them into the proper format so they can be added back.

wgro commented 10 years ago

Just a quick FYI...

I'm still getting an error (new one) using 1.0.1:

Oops! The server said: ArgumentError at /email_processor ================================= > wrong number of arguments (1 for 0) /usr/local/Cellar/rbenv/0.4.0/versions/2.1.2/lib/ruby/gems/2.1.0/gems/griddler-1.0.0/app/controllers/griddler/emails_controller.rb, line 19 ------------------------------------------------------------------------------------------------------------------------------------------- ``` ruby 14 def normalized_params 15 Array.wrap(email_service.normalize_params(params)) 16 end 17 18 def process_email(email) > 19 processor_class.new(email).public_send(processor_method) 20 end 21 22 def griddler_configuration 23 Griddler.configuration 24 end ``` App backtrace ------------- Full backtrace -------------- - /usr/local/Cellar/rbenv/0.4.0/versions/2.1.2/lib/ruby/gems/2.1.0/gems/griddler-1.0.0/app/controllers/griddler/emails_controller.rb:19:in `process_email' - /usr/local/Cellar/rbenv/0.4.0/versions/2.1.2/lib/ruby/gems/2.1.0/gems/griddler-1.0.0/app/controllers/griddler/emails_controller.rb:4:in `block in create' - /usr/local/Cellar/rbenv/0.4.0/versions/2.1.2/lib/ruby/gems/2.1.0/gems/griddler-1.0.0/app/controllers/griddler/emails_controller.rb:3:in `create' - actionpack (4.1.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action' - actionpack (4.1.0) lib/abstract_controller/base.rb:189:in `process_action' - actionpack (4.1.0) lib/action_controller/metal/rendering.rb:10:in `process_action' - actionpack (4.1.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action' - activesupport (4.1.0) lib/active_support/callbacks.rb:113:in `call' - activesupport (4.1.0) lib/active_support/callbacks.rb:229:in `block in halting' - activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `block in halting' - activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `block in halting' - activesupport (4.1.0) lib/active_support/callbacks.rb:86:in `run_callbacks' - actionpack (4.1.0) lib/abstract_controller/callbacks.rb:19:in `process_action' - actionpack (4.1.0) lib/action_controller/metal/rescue.rb:29:in `process_action' - actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action' - activesupport (4.1.0) lib/active_support/notifications.rb:159:in `block in instrument' - activesupport (4.1.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument' - activesupport (4.1.0) lib/active_support/notifications.rb:159:in `instrument' - actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action' - actionpack (4.1.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action' - activerecord (4.1.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action' - actionpack (4.1.0) lib/abstract_controller/base.rb:136:in `process' - actionview (4.1.0) lib/action_view/rendering.rb:30:in `process' - actionpack (4.1.0) lib/action_controller/metal.rb:195:in `dispatch' - actionpack (4.1.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch' - actionpack (4.1.0) lib/action_controller/metal.rb:231:in `block in action' - actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch' - actionpack (4.1.0) 

etc etc...
bradpauly commented 10 years ago

It's working ok for me, however, I'm not using the built-in controller. From the error message it looks like it might be your processor class. This line:

processor_class.new(email).public_send(processor_method)

Does your processor class expect an argument for the initialize method?

wgro commented 10 years ago

Okay, I just realized I goofed on something. I'll try my tests again.

Edit: aaaaaaand it worked. Thanks so much for your patience.

bradpauly commented 10 years ago

Great, no problem. Sorry about the bug and glad you got it working.