Joel VanderWerf wrote:
>
> This patch preserves more of the information carried by exceptions that
> bubble up from particular database libraries and are handled by sequel,
> so that you don't have to parse and match message strings.
On second thought, it's hard to preserve the original exception object
and at the same time display the exception in the backtrace in the same
form as usual, which you would want to avoid breaking code....
If you use the code below, then the first line of the backtrace is:
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/errors.rb:62:in
`check': database is locked (Sequel::DatabaseError)
instead of:
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/errors.rb:62:in
`check': SQLite3::BusyException: database is locked (Sequel::DatabaseError)
However, on the plus side, the #inspect output is the same, and you can
use the message to match against exception classes. I think that's a
positive tradeoff, but YMMV.
module Sequel
class DatabaseError
def inspect
case m=message
when Exception
"#<#{self.class}: #{m.inspect}>"
else
super
end
end
end
class Database
# Convert the given exception to a DatabaseError, keeping message
# and traceback.
def raise_error(exception, opts={})
if !opts[:classes] || Array(opts[:classes]).any?{|c|
exception.is_a?(c)}
c = (opts[:disconnect] ? DatabaseDisconnectError : DatabaseError)
raise c, exception, exception.backtrace
else
raise exception
end
end
end
end
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---