1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

StatementInvalid takes WrappedDatabaseException's place

This commit is contained in:
Jeremy Kemper 2013-04-23 17:26:16 -07:00
parent 226de24fa2
commit 60bb1333c6
3 changed files with 13 additions and 12 deletions

View file

@ -433,7 +433,7 @@ module ActiveRecord
def translate_exception(exception, message) def translate_exception(exception, message)
# override in derived class # override in derived class
ActiveRecord::StatementInvalid.new(message) ActiveRecord::StatementInvalid.new(message, exception)
end end
end end
end end

View file

@ -287,7 +287,7 @@ module ActiveRecord
end end
rescue ActiveRecord::StatementInvalid => exception rescue ActiveRecord::StatementInvalid => exception
if exception.message.split(":").first =~ /Packets out of order/ if exception.message.split(":").first =~ /Packets out of order/
raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings." raise ActiveRecord::StatementInvalid.new("'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings.", exception.original_exception)
else else
raise raise
end end

View file

@ -57,24 +57,25 @@ module ActiveRecord
class RecordNotDestroyed < ActiveRecordError class RecordNotDestroyed < ActiveRecordError
end end
# Raised when SQL statement cannot be executed by the database (for example, it's often the case for # Superclass for all database execution errors.
# MySQL when Ruby driver used is too old). #
# Wraps the underlying database error as +original_exception+.
class StatementInvalid < ActiveRecordError class StatementInvalid < ActiveRecordError
attr_reader :original_exception
def initialize(message, original_exception = nil)
super(message)
@original_exception = original_exception
end
end end
# Raised when SQL statement is invalid and the application gets a blank result. # Raised when SQL statement is invalid and the application gets a blank result.
class ThrowResult < ActiveRecordError class ThrowResult < ActiveRecordError
end end
# Parent class for all specific exceptions which wrap database driver exceptions # Defunct wrapper class kept for compatibility.
# provides access to the original exception also. # +StatementInvalid+ wraps the original exception now.
class WrappedDatabaseException < StatementInvalid class WrappedDatabaseException < StatementInvalid
attr_reader :original_exception
def initialize(message, original_exception)
super(message)
@original_exception = original_exception
end
end end
# Raised when a record cannot be inserted because it would violate a uniqueness constraint. # Raised when a record cannot be inserted because it would violate a uniqueness constraint.