customink / central_logger

Ruby Mongo DB Logger for Rails - centralized logging for rails apps in MongoDB. Converted to gem, added global exception logging, and added Rails 3 (or 2) support.
http://blog.philburrows.com/articles/2009/09/28/rails-logging-with-mongodb/
MIT License
128 stars 35 forks source link

Bug fix: filter tempfiles from params to avoid BSON::InvalidDocument errors #5

Closed trevorturk closed 13 years ago

trevorturk commented 13 years ago

This was an important bug fix for my apps at least.

It avoids an error that I was seeing a lot of: "Cannot serialize an object of class Tempfile into BSON (BSON::InvalidDocument)" by filtering tempfiles from params.

Again, let me know your level of interest, and/or if you'd like any help.

astupka commented 13 years ago

I was looking at the bson gem in order to make this work generically. The bson_ruby.rb file has a bson_type method, but it throws an InvalidDocument exception if it can't map the ruby type to a bson type vs returning some sort of invalid type flag.

It seems like the easiest way to have this work generically for now is to run through the params and catch the InvalidDocumentException from bson_type then insert something similar to what you are using (ex. object type as string). I believe this would work for your case as well.

trevorturk commented 13 years ago

So, for each element in the params hash, we'd test if it can be serialized and, if not, store a note about the exception or type of object or something? That sounds good to me - I was thinking that this problem might not be limited to Tempfiles.

trevorturk commented 13 years ago

FWIW - I'm trying a more generic solution out over here: https://github.com/trevorturk/central_logger/tree/filter_params

I'm not sure if it's going to work, but I've been getting "BSON::InvalidStringEncoding: String not valid UTF-8" errors in Hoptoad, so this is an attempt to fix things up more generically as you mentioned.

trevorturk commented 13 years ago

This appears to have been fixed. Thanks!