16 February 2012

Mind your rescue magic

Rescue someone unwilling to look after himself, and he will cling to you like a dangerous illness.

--Mason Cooley
It is always a good practice to rescue exceptions in Ruby, but be aware that, keep best the practices all times even when you are doing your rescue magic.

Let us take a look at the following code:

begin
  HTTParty.get(@url, :timeout => 5)
rescue
  "Time out!"
end

14 February 2012

Nokogiri Segmentation Fault on Mac Lion

I have a web project running on ruby-1.8.7-p352 with Nokogiri 1.5.0. It works well until I incidentally did a system update. When I started rails server, tried to access my website, the server would throw an exception and abort. The error message I got was like the following:
nokogiri-1.5.0/lib/nokogiri/xml/node.rb:930: [BUG] Segmentation fault
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.2.0]
The Nokogiri information was like the following:
# Nokogiri (1.5.0)
    --- 
    warnings: []
    
    ruby: 
      engine: mri
      version: 1.8.7
      description: ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.2.0]
      platform: i686-darwin11.2.0
    libxml: 
      loaded: 2.7.3
      binding: extension
      compiled: 2.7.3
    nokogiri: 1.5.0