-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
I had a before_save callback that accidentally returned false, so no errors were added onto the model. This is the error I received after calling save!:
Mongoid::Errors::Validations: Validation failed - .
Given that the error class contains Validation, and the message contains 'Validation', I expected that a field was invalid, not that a callback returned false. I looked this error up in github issues and found a completely unrelated problem MONGOID-442. Obviously the root of this problem is a bad API design of ActiveModel where there is both a return value and an errors object that indicates an error. However, I am hoping for a better differentiation in error messages. In ActiveRecord, an actual validation error raises:ActiveRecord::RecordInvalid, whereas a before_save that returns false raises: ActiveRecord::RecordNotSaved. An ideal error message would be even more hepful, something like: Mongoid::Errors::Callback