-
Type: Task
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Docs
-
None
CommandFailedEvent::getError() is documented as returning "the Exception associated with the failed command". It's reasonable to expect this will be the same exception thrown by the operation itself; however, that will generally not be the case.
For phongo_execute_command, phongo_throw_exception_from_bson_error_t_and_reply() is always used and will conditionally use a CommandException to provide access to the command response. That may also be the case for phongo_execute_query, since phongo_cursor_advance_and_check_for_error uses the same function.
For phongo_execute_bulk_write, phongo_throw_exception_from_bson_error_t_and_reply will be used for errors not in the MONGOC_ERROR_SERVER or MONGOC_ERROR_WRITE_CONCERN domains. Otherwise, a BulkWriteException is thrown to provide access to an intermediate write result.
For the above cases, CommandFailedEvent::getError() will return a ServerException instead of a CommandException or BulkWriteException. For CommandException, this is probably fine because the command response is already accessible on CommandFailedEvent. As for BulkWriteException, the intermediate write result is not available in APM so we have no other alternative.
There is likely nothing to fix here, but we'd do well to document this so users do not expect to see the same exception.