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

Exceptions as Flow Control Performance Problem

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.3.1
    • Affects Version/s: None
    • Component/s: None

      Mongoid::Extensions::ObjectId::Conversions#convert calls BSON::ObjectId.from_string, which raises BSON::InvalidObjectId if the supplied argument is illegal.

      This is a real-world performance problem.

      Raising makes sense for BSON::ObjectId.from_string, if the method expects callers only to pass BSON::ObjectId.legal? arguments. Ideally, BSON::ObjectId would provide another method for trying the conversion without raising (e.g., returning nil rather than raising in case of illegal argument).

      But it doesn't make sense for Mongoid::Extensions::ObjectId::Conversions#convert to use this raising as flow control. Rather, at the very least, #convert should check that the argument is BSON::ObjectId.legal? before trying to convert it. #convert should avoid permitting BSON::ObjectId.from_string to raise unless that would really be an error (and not simply something #convert catches).

            Assignee:
            durran Durran Jordan
            Reporter:
            yfeldblum yfeldblum
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: