views:

37

answers:

1

I've got some strange errors happening in my rails app and I'm trying to log better errors instead of the whole stack of passenger stuff that I don't care about. I thought I would do this with a Rescue clause and explicit error handling, like logging the params hash. But I'm concerned if this would interrupt any rollback that is happening. For that matter, I'm assuming rollbacks automatically occur when an error occurs as part of the normal rails error handling, but I haven't been able to find that documented anywhere. I'm using Dreamhost with MySQL, so I thought transactions and rollbacks were happening there.

A: 

This is not very advisable (to put a big begin-rescue on your code).

Why don't you use backtrace silencers? (from Rails 2.3) http://afreshcup.com/home/2008/11/29/rails-23-backtrace-silencing.html.

From release notes:

Rails automatically adds silencers to get rid of the most common noise in a new application, and builds a config/backtrace_silencers.rb file to hold your own additions

If you use an earlier version of Rails, use http://github.com/thoughtbot/quietbacktrace.

Vlad Zloteanu
thanks, this is helpful for the noisy stacktrace, but doesn't answer the original question regarding the rollback; for that matter, why is it not advisable to put a big begin-rescue in my code?
Well.. it is advisable as long as you re-raise the error. Rails handles some special cases (EG ActiveRecord::RecordNotFound is rescued for public requests and a 404 header is returned instead).
Vlad Zloteanu