diff options
author | Jeremy Daer <jeremydaer@gmail.com> | 2016-04-18 17:29:43 -0700 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2016-04-18 17:31:28 -0700 |
commit | 446190fbd2e1878fa321579f9114496ed8ce44e8 (patch) | |
tree | ea688ca3bbdd719fa154d236c6c765274a362d6e /activerecord/lib | |
parent | b36078fb8bf1a34e29bb4f029399c6428ca011ef (diff) | |
parent | 6efd02e2302186f463ca82bec4a9cf2b8ce981ec (diff) | |
download | rails-446190fbd2e1878fa321579f9114496ed8ce44e8.tar.gz rails-446190fbd2e1878fa321579f9114496ed8ce44e8.tar.bz2 rails-446190fbd2e1878fa321579f9114496ed8ce44e8.zip |
Merge pull request #23522 from kamipo/add_value_too_long_exception_class
Add `ActiveRecord::ValueTooLong` exception class
Diffstat (limited to 'activerecord/lib')
3 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 6fc286f2be..86ad422b06 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -716,6 +716,8 @@ module ActiveRecord RecordNotUnique.new(message) when 1452 InvalidForeignKey.new(message) + when 1406 + ValueTooLong.new(message) else super end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 061a9f66d4..d7f9378a4e 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -406,6 +406,7 @@ module ActiveRecord protected # See http://www.postgresql.org/docs/current/static/errcodes-appendix.html + VALUE_LIMIT_VIOLATION = "22001" FOREIGN_KEY_VIOLATION = "23503" UNIQUE_VIOLATION = "23505" @@ -417,6 +418,8 @@ module ActiveRecord RecordNotUnique.new(message) when FOREIGN_KEY_VIOLATION InvalidForeignKey.new(message) + when VALUE_LIMIT_VIOLATION + ValueTooLong.new(message) else super end diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index 2ec9bf3d67..b8b8684cff 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -125,6 +125,10 @@ module ActiveRecord class InvalidForeignKey < WrappedDatabaseException end + # Raised when a record cannot be inserted or updated because a value too long for a column type. + class ValueTooLong < StatementInvalid + end + # Raised when number of bind variables in statement given to +:condition+ key # (for example, when using {ActiveRecord::Base.find}[rdoc-ref:FinderMethods#find] method) # does not match number of expected values supplied. |