aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-11 09:41:24 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-11 09:41:24 +0000
commit57070277b420819b9bf0980e1a794a587f31dff6 (patch)
tree794a149d7a75e219bee6b8bbae8b57640414e0ae /activerecord/lib/active_record
parentffbaf1c5ff50a12514405ced230a2bd76f6405fe (diff)
downloadrails-57070277b420819b9bf0980e1a794a587f31dff6.tar.gz
rails-57070277b420819b9bf0980e1a794a587f31dff6.tar.bz2
rails-57070277b420819b9bf0980e1a794a587f31dff6.zip
Added better exception error when unknown column types are used with migrations #1814 [fbeausoleil@ftml.net]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2201 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/base.rb6
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/abstract_adapter.rb9
2 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index e0bce194b2..2d7cd6c17a 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -28,7 +28,9 @@ module ActiveRecord #:nodoc:
end
class ConfigurationError < StandardError #:nodoc:
end
-
+ class UnknownTypeError < ActiveRecordError #:nodoc:
+ end
+
class AttributeAssignmentError < ActiveRecordError #:nodoc:
attr_reader :exception, :attribute
def initialize(message, exception, attribute)
@@ -222,6 +224,8 @@ module ActiveRecord #:nodoc:
# objects that should be inspected to determine which attributes triggered the errors.
# * +AttributeAssignmentError+ -- an error occurred while doing a mass assignment through the +attributes=+ method.
# You can inspect the +attribute+ property of the exception object to determine which attribute triggered the error.
+ # * +UnknownTypeError+ -- Raised when AbstractAdapter#type_to_sql cannot map the type given to a native type.
+ #
# *Note*: The attributes listed are class-level attributes (accessible from both the class and instance level).
# So it's possible to assign a logger to the class through Base.logger= which will then be used by all
# instances in the current object space.
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index f5aa09c1f2..5f9f99b0b2 100755
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -431,7 +431,14 @@ module ActiveRecord
end
def type_to_sql(type, limit = nil)
- native = native_database_types[type]
+ unless native = native_database_types[type]
+ raise(
+ ActiveRecord::UnknownTypeError,
+ "Unable to convert type '#{type}' to a native type. " +
+ "Valid options: #{native_database_types.keys.to_sentence}"
+ )
+ end
+
limit ||= native[:limit]
column_type_sql = native[:name]
column_type_sql << "(#{limit})" if limit