Please sign in to comment.
Raise Sequel::DatabaseError instead of generic Sequel::Error for data…
…base errors, don't swallow tracebacks This commit adds a new exception class, Sequel::DatabaseError. This exception class should be used for all errors that come from the database, such as invalid syntax in a query or database access rights violation. This commit adds a couple private Database methods, raise_error and transaction_error. raise_error converts the exception to a DatabaseError, keeping the previous exception message (prepended with the previous exception class) as well as the traceback. If an optional :classes option is passed, it only converts the exception if it is one of those classes. transaction_error calls raise_error with the :classes options set to the array of passed classes, unless the error is an Error::Rollback. These DRY up some code in the adapters. This commit also removes the convert_pgerror method for the postgres adapter, since it is no longer necessary. This is a backwards incompatible change for SQLite users, since the SQLite adapter previously raised Error::InvalidStatement instead of just Error.
- Loading branch information...
Showing with 37 additions and 19 deletions.
- +2 −0 CHANGELOG
- +1 −1 lib/sequel_core/adapters/db2.rb
- +2 −2 lib/sequel_core/adapters/jdbc.rb
- +1 −1 lib/sequel_core/adapters/jdbc/postgresql.rb
- +2 −2 lib/sequel_core/adapters/mysql.rb
- +2 −2 lib/sequel_core/adapters/postgres.rb
- +3 −8 lib/sequel_core/adapters/shared/postgres.rb
- +2 −2 lib/sequel_core/adapters/sqlite.rb
- +18 −1 lib/sequel_core/database.rb
- +4 −0 lib/sequel_core/exceptions.rb