diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-13 07:13:23 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-07 16:14:42 +0900 |
commit | 20da6c7eac90526e1f93f8463bd5e12d1e6203a3 (patch) | |
tree | 8d2931a0402dcf771b65b781a92d249d25635d84 /actionpack/lib/action_dispatch.rb | |
parent | c9e4c848eeeb8999b778fa1ae52185ca5537fffe (diff) | |
download | rails-20da6c7eac90526e1f93f8463bd5e12d1e6203a3.tar.gz rails-20da6c7eac90526e1f93f8463bd5e12d1e6203a3.tar.bz2 rails-20da6c7eac90526e1f93f8463bd5e12d1e6203a3.zip |
Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options
When I've added new `:size` option in #35071, I've found that invalid
`:limit` and `:precision` raises `ActiveRecordError` unlike other
invalid options.
I think that is hard to distinguish argument errors and statement
invalid errors since the `StatementInvalid` is a subclass of the
`ActiveRecordError`.
https://github.com/rails/rails/blob/c9e4c848eeeb8999b778fa1ae52185ca5537fffe/activerecord/lib/active_record/errors.rb#L103
```ruby
begin
# execute any migration
rescue ActiveRecord::StatementInvalid
# statement invalid
rescue ActiveRecord::ActiveRecordError, ArgumentError
# `ActiveRecordError` except `StatementInvalid` is maybe an argument error
end
```
I'd say this is the inconsistency worth fixing.
Before:
```ruby
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
```
After:
```ruby
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
```
Diffstat (limited to 'actionpack/lib/action_dispatch.rb')
0 files changed, 0 insertions, 0 deletions