[Nitro] Question about error handling in *Store

Bryan Soto bryan.a.soto at gmail.com
Wed Apr 26 16:18:12 EDT 2006

On 4/26/06, gabriele renzi <surrender_it at yahoo.it> wrote:
> Hi people,
> I notice that all the Og::Store subclasses are defined in files with an
> header similar to
> begin
>    require 'sqlite'
> rescue Object => ex
>    Logger.error 'Ruby-Sqlite bindings are not installed!'
>    Logger.error ex
> end

$ grep -R 'rescue Object' nitro/* glue/* og/* gen/*
nitro/lib/glue/sweeper.rb:    rescue Object
nitro/lib/nitro/compiler/script.rb:    rescue Object
nitro/lib/nitro/helper/debug.rb:    rescue Object
nitro/lib/nitro/adapter/mongrel.rb:    rescue Object => ex
nitro/lib/nitro/adapter/scgi.rb:            rescue Object
nitro/lib/nitro/adapter/scgi.rb:                rescue Object
nitro/lib/nitro/adapter/webrick.rb:              rescue Object => ex
nitro/lib/nitro/adapter/webrick.rb:    rescue Object => ex
nitro/lib/nitro/caching/output.rb:      rescue Object => ex
nitro/lib/nitro/helper.rb:            rescue Object
nitro/proto/script/scgi_service:        rescue Object => nitro_error
nitro/proto/script/scgi_ctl:    rescue Object
nitro/test/nitro/tc_session.rb:  rescue Object # Errno::EBADF => e
glue/lib/glue/configuration.rb:        rescue Object
glue/lib/glue/mailer/outgoing.rb:          rescue Object => e
og/lib/og/store/sqlite2.rb:rescue Object => ex
og/lib/og/store/sqlite2.rb:    rescue Object
og/lib/og/store/sqlite2.rb:    rescue Object => ex
og/lib/og/store/sqlite2.rb:        rescue Object => ex
og/lib/og/store/alpha/sqlserver.rb:rescue Object => ex
og/lib/og/store/kirby.rb:rescue Object => ex
og/lib/og/store/kirby.rb:      rescue Object
og/lib/og/store/sqlite.rb:rescue Object => ex
og/lib/og/store/sqlite.rb:    rescue Object
og/lib/og/store/sqlite.rb:        rescue Object => ex
og/lib/og/store/mysql.rb:rescue Object => ex
og/lib/og/store/mysql.rb:  rescue Object => ex
og/lib/og/store/psql.rb:rescue Object => ex
og/test/og/tc_cacheable.rb:rescue Object

It's a general tendency of George's. I can confirm this as my original
capture of Errno::EBADF here was changed.

nitro/test/nitro/tc_session.rb:  rescue Object # Errno::EBADF => e

> There are two things I found strange in this, first, it seems excessive
> to hide all possible exceptions by rescueing Object, I think that
> LoadError would be a better fit; second, I 'm not sure I undesrtand why
> the problem is just logged instead of letting the application crash,
> because in most cases there will be a crash whenever something is done
> that is store related,  by referencing a a nil object.

Personally, I tend to agree that exception handling should be as
specific as possible. Differing philosophies, I suppose. But you make
a very good point on the stores I think.

> It seem to me that this is a bad thing and that a crash-early approach
> would be better and allow faster diagnostics, but maybe there is
> something I have overlooked.

Anyone have any objections to changing this? Seems to be a bug to me.

> Someone who would like to still use the application withouth having a
> real reference to a Store could just create an empty foo.rb in src/ and
> go on anyway.

That is equivalent to what we're currently doing, isn't it. :)


"Never tell people how to do things. Tell them what to do and they
will surprise you with their ingenuity." —General George S. Patton

More information about the Nitro-general mailing list