mongodb/mongoid · error · Mongoid::Errors::Validations
Validation of failed.
Error message
Validation of %{document} failed. What it means
Raised by fail_due_to_validation! (invoked from save! and update!) when the document fails validation. The raised Errors::Validations wraps the document's errors object, which enumerates the failing validators.
Solutions
- Inspect error.document.errors.full_messages to see which validations failed
- Fix the invalid attributes or relax/adjust the validations
- Call save/update without bang to get a false return instead of an exception
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at lib/mongoid/persistable.rb:130 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mongodb/mongoid@0da0e23d71 (2026-08-23).
Data as JSON: /api/errors/96efeaeab4f6b516.
Report an issue: GitHub.
Appendix: source
Thrown at lib/mongoid/persistable.rb:130
_mongoid_reset_atomic_context_changes! if has_own_context
raise e
ensure
_mongoid_pop_atomic_context if has_own_context
if call_depth.zero?
@atomic_depth = nil
@atomic_updates_to_execute_stack = nil
end
end
# Raise an error if validation failed.
#
# @example Raise the validation error.
# Person.fail_due_to_validation!(person)
#
# @raise [ Errors::Validations ] The validation error.
def fail_due_to_validation!
raise Errors::Validations.new(self)
end
# Raise an error if a callback failed.
#
# @example Raise the callback error.
# Person.fail_due_to_callback!(person, :create!)
#
# @param [ Symbol ] method The method being called.
#
# @raise [ Errors::Callback ] The callback error.
def fail_due_to_callback!(method)
raise Errors::Callback.new(self.class, method)
end
private
# Are we executing an atomically block on the current document?
#View on GitHub (pinned to 0da0e23d71)