Skip to content

Commit 04fb8f8

Browse files
committed
Construct UnknownAttribute error message uniformly
1 parent 29b6fcd commit 04fb8f8

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

lib/dynamoid/errors.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,16 @@ class InvalidQuery < Error; end
8686

8787
class UnsupportedKeyType < Error; end
8888

89-
class UnknownAttribute < Error; end
89+
class UnknownAttribute < Error
90+
attr_reader :model_class, :attribute_name
91+
92+
def initialize(model_class, attribute_name)
93+
super("Attribute #{attribute_name} does not exist in #{model_class}")
94+
95+
@model_class = model_class
96+
@attribute_name = attribute_name
97+
end
98+
end
9099

91100
class SubclassNotFound < Error; end
92101

lib/dynamoid/fields.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def write_attribute(name, value)
291291
old_value = read_attribute(name)
292292

293293
unless attribute_is_present_on_model?(name)
294-
raise Dynamoid::Errors::UnknownAttribute, "Attribute #{name} is not part of the model"
294+
raise Dynamoid::Errors::UnknownAttribute.new(self.class, name)
295295
end
296296

297297
if association = @associations[name]

lib/dynamoid/persistence/update_validations.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ module UpdateValidations
77
def self.validate_attributes_exist(model_class, attributes)
88
model_attributes = model_class.attributes.keys
99

10-
attributes.each_key do |attr_name|
11-
unless model_attributes.include?(attr_name)
12-
raise Dynamoid::Errors::UnknownAttribute, "Attribute #{attr_name} does not exist in #{model_class}"
10+
attributes.each_key do |name|
11+
unless model_attributes.include?(name)
12+
raise Dynamoid::Errors::UnknownAttribute.new(model_class, name)
1313
end
1414
end
1515
end

0 commit comments

Comments
 (0)