Archive for September, 2009
Rails 2.3 BacktraceCleaner and TextMate
Start from Rails 2.3, it includes a new class called BacktraceCleaner:
Many backtraces include too much information that’s not relevant for the context. This makes it hard to find the signal in the backtrace and adds debugging time. With a BacktraceCleaner, you can setup filters and silencers for your particular context, so only the relevant lines are included.
Here’s how it works:
bc = BacktraceCleaner.new
bc.add_filter { |line| line.gsub(Rails.root, ”) }
bc.add_silencer { |line| line =~ /mongrel|rubygems/ }
bc.clean(exception.backtrace) # will strip the Rails.root prefix and skip any lines from mongrel or rubygems
Which is simple, great and smart, well, most of the time.
If you are a hardcore TextMate fan, like me, and you like using command+R to run your ruby code/test, you will find you can’t open files by clicking the backtrace list links on the result window. Actually, you still can, but instead of opening the file you want, it opens a new window with a empty new file.
The reason is simple, BacktraceCleaner has a default filter “line.gsub(Rails.root, ”)”. It removes your project path from file full name.
Solution is simple too:
- Remove “add_filter { |line| line.sub(“#{RAILS_ROOT}/”, ”) }” from “vendor/rails/railties/lib/rails/backtrace_cleaner.rb”
- Add “Rails.backtrace_cleaner.add_filter { |line| line.sub(“#{RAILS_ROOT}/”, ”) } unless RAILS_ENV == ‘test’” to “config/initializers/backtrace_silencers.rb”
That’s it. Is it a bug for Rails, or not?
Did You Know 4.0
This is another official update from XPlane to the original “Shift Happens” video. This completely new Fall 2009 version includes facts and stats focusing on the changing media landscape, including convergence and technology.
Anyway, if you don’t know, you should know!