Wednesday, July 31, 2013

Aibrake , Rack , Session_off ...

After installing Airbrake gem my collection's request Rspec.specs stoped working as expected.

I encounterd this error:

RuntimeError: can't add a new key into hash during iteration
Since Ruby 1.9(.3?) you cant modify Hash within iteration. ( even if they are ordered )

After some hours spent in debugger, I found that Airbrake gem Notification class uses Rack's Request @env variable to collect params for Aibrake/Errbit notification. Nothing weird here, but while collecting params in a loop , the clean_params method hit the racks request's @env with the #cookies method, in order to obtain the cookie hash. Code below :

Loading ....
I think that this is what misslead ThoughtBot guys, this method is available form the class Api ( I mean not private ) and returns the cookie Hash, but it also have side effects ... Sadly , it mutates the @env. I can't say if this is bad design or not, but it looks weird to mee.

In order to get this working I submitted a fix to Airbrake, not to Rack ...
Last words, thanks to ThoughBot guys, for all the opensource tools they provide, and reactivity to merge contribs.