Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2462

Don't return null from mongoc_collection_find_indexes

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.10.0
    • Affects Version/s: None
    • Component/s: libmongoc
    • None
    • None
    • Fully Compatible
    • None
    • None
    • None
    • None
    • None
    • None

      Generally, when a function can return a mongoc_cursor_t, it should always return a mongoc_cursor_t, never NULL. On error, the function should set the cursor's error, and return the cursor.

      The old function mongoc_collection_find_indexes was implemented incorrectly, it can return NULL on error.

      I implemented a new function, mongoc_collection_find_indexes_with_opts, which behaves the way we want: it always returns a cursor, never NULL.

      I then rewrote the old mongoc_collection_find_indexes to use the new function mongoc_collection_find_indexes_with_opts, but I preserved the bad old behavior: the old function returns NULL on error.

      acm convinced me that it's ok to fix the old function mongoc_collection_find_indexes, so that it never returns NULL. This is an API change, but it is not an API break. If a user's application was written for the old API, it must check that the cursor is not NULL, and also check if mongoc_cursor_error (cursor, &error); returns true. We can update the old function so it never returns NULL, and a user's application will still work correctly without changes.

      So, don't return NULL, and update any tests that must change to verify the desired new behavior. Check the documentation and see if it requires an update.

            Assignee:
            xiangyu.yao@mongodb.com Xiangyu Yao (Inactive)
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: