Skip to content

Commit bee7100

Browse files
committed
MONGOID-5222 update error message and docs
1 parent 78c5ee9 commit bee7100

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

lib/config/locales/en.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ en:
373373
resolution: "Set the values from the parent, or redefine the association
374374
with only a single definition in the parent."
375375
invalid_value:
376-
message: "Value of type %{value_class} cannot be written to a field of type %{field_class}"
377-
summary: "Tried to set a value of type %{value_class} to a field of type %{field_class}"
378-
resolution: "Verify if the value to be set correspond to field definition"
376+
message: "The value %{value} cannot be written to a field of type %{field_class}"
377+
summary: "The value %{value} could not be coerced to type %{field_class}"
378+
resolution: "Verify that the value to be set corresponds to the field definition"
379379
mixed_relations:
380380
message: "Referencing a(n) %{embedded} document from the %{root}
381381
document via a non-embedded association is not allowed since the

lib/mongoid/errors/invalid_value.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ module Errors
77
# For example when try to set an Array value to a Hash attribute.
88
#
99
class InvalidValue < MongoidError
10-
def initialize(field_class, value_class)
10+
11+
# Create the new error.
12+
#
13+
# @param [ Class ] field_class The class of the field attempting to be
14+
# assigned to.
15+
# @param [ Object ] value The value being assigned.
16+
#
17+
# @api private
18+
def initialize(field_class, value)
1119
super(
12-
compose_message("invalid_value", { value_class: value_class, field_class: field_class })
20+
compose_message("invalid_value", { value: value, field_class: field_class })
1321
)
1422
end
1523
end

lib/mongoid/extensions/object.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _mongoid_wrap_mongoize(object)
244244
return if object.nil?
245245
yield.tap do |res|
246246
if res.nil?
247-
raise Errors::InvalidValue.new(self, object.class)
247+
raise Errors::InvalidValue.new(self, object)
248248
end
249249
end
250250
end

0 commit comments

Comments
 (0)