[CDRIVER-2462] Don't return null from mongoc_collection_find_indexes Created: 11/Jan/18  Updated: 28/Oct/23  Resolved: 25/Jan/18

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: None
Fix Version/s: 1.10.0

Type: Improvement Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: Xiangyu Yao (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

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.



 Comments   
Comment by Githook User [ 25/Jan/18 ]

Author:

{'name': 'Xiangyu Yao', 'email': 'xiangyu.yao24@gmail.com', 'username': 'xy24'}

Message: CDRIVER-2462 mongoc_collection_find_indexes won't return null
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/ee6f975e6111675bfed3f780eb86502c5b86e0e8

Comment by Xiangyu Yao (Inactive) [ 25/Jan/18 ]

code review url: https://mongodbcr.appspot.com/178610001/

Generated at Wed Feb 07 21:15:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.