When SQLite3::Database.new fails to establish a database connection, the resulting exception does not report the underlying
cause. For example:
$ ruby -r sqlite3 -e 'SQLite3::Database.new("/no/such/path/db")'
The result is a generic exception:
could not open database (SQLite3::CantOpenException)
In this case, the underlying cause that the SQLite3 library reports is "unable to open database file". This
information, however, is never requested by the Ruby wrapper because the connection handle (which SQLite3 returns even
if sqlite3_open() fails) is not passed through to the wrapper's generic Error.check routine.
Enclosed is a tiny patch that fixes the problem. After applying it, we get the full details of the failure:
could not open database: unable to open database file (SQLite3::CantOpenException)
Cheers,
Tom Moertel <tom@moertel.com>
|