-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Error Handling
Currently when a user attempts to use a newly instantiated Client, they currently receive topology.ErrTopologyClosed error. This is confusing for users of the high level API since they don't have in-depth knowledge of a topology. We can solve this in one of two ways:
- Check for ErrTopologyClosed and transform it into a ErrClientDisconnected error
Add a connection state to Client and check if the Client is connected before performing an operation.
While the second option provides a faster path to failure and is less invasive, it introduces a race condition, where users that call Disconnect might still see a topology.ErrTopologyClosed error. Eventually, we'll need to wrap most of the core API packages' errors, so starting with ErrTopologyClosed seems like a sensible thing to do.
A general error handling function can be created in the mongo package or attached to the *mongo.Collection type to handle the transformation.