Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-910

when a callback just returns false the error message is not useful

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.2.0
    • 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

            Assignee:
            Unassigned Unassigned
            Reporter:
            gregwebs gregwebs
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: