awesome-print / awesome_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
http://github.com/michaeldv/awesome_print
MIT License
4.07k stars 454 forks source link

Strict mass-assignment protection preventing display of object. #318

Open MrJoy opened 7 years ago

MrJoy commented 7 years ago
(pry) output error: #<ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hash>

Unfortunately, for historical reasons, our Rails app has some data serialized to a text column named data as YAML that includes a class of ActionController::Parameters, and a def data method that does a YAML.load of the raw attribute.

When we try to display the offending model at the console, we get the above and no other output. No useful stack trace, no meaningful info about the object, etc. The inspect method for the model works fine, because it's displaying the column attribute (I.E. a String), not the parsed YAML.

While this is a pathological design problem on our end, the failure mode of not displaying anything is an impediment to debugging.

Perhaps you could catch exceptions, and try falling back to inspect? Or maybe provide more context about what went wrong (I.E. the path into the object at which the exception occurred)?

Or, perhaps propagate the error in a way where Pry's _ex_ is properly set?

obourdon commented 4 years ago

@MrJoy @CentroDL @ndbroadbent may be the last 2 commits in my from are doing what you expected (somehow)

ndbroadbent commented 4 years ago

Thanks @obourdon, this would be great to merge in! I’m always getting this error while debugging a controller action and trying to see the params.

MrJoy commented 4 years ago

I honestly don't even remember this issue -- and am no longer at the organization that was experiencing it. That said, your changes certainly look like they would help. Thank you!

csalvato commented 4 years ago

@obourdon I think that here:

https://github.com/obourdon/awesome_print/commit/5567d544b9c83a29b9e889d38a9c37cbe994480e

you would want to be able to call object.to_enum.to_h which is what will turn the Parameters to a hash. but then you lose out on the permitted:true attribute. 🤔