@@ -299,6 +299,25 @@ MongoClient within the callback in order to execute operations within the
299
299
transaction. Per the `Driver Session `_ specification, ClientSessions should
300
300
already provide access to a client object.
301
301
302
+ Handling errors inside the callback
303
+ -----------------------------------
304
+
305
+ Drivers MUST document that the callback MUST NOT silently handle command errors
306
+ without allowing such errors to propagate. Command errors may abort the transaction
307
+ on the server, and an attempt to commit the transaction will be rejected with
308
+ ``NoSuchTransaction `` error.
309
+
310
+ For example, ``DuplicateKeyError `` is an error that aborts a transaction on the
311
+ server. If the callback catches ``DuplicateKeyError `` and does not re-throw it,
312
+ the driver will attempt to commit the transaction. The server will reject the
313
+ commit attempt with ``NoSuchTransaction `` error. This error has the
314
+ "TransientTransactionError" label and the driver will retry the commit. This
315
+ will result in an infinite loop.
316
+
317
+ Drivers MUST recommend that the callback re-throw command errors if they
318
+ need to be handled inside the callback. Drivers SHOULD also recommend using
319
+ Core Transaction API if a user wants to handle errors in a custom way.
320
+
302
321
Test Plan
303
322
=========
304
323
@@ -494,6 +513,7 @@ client-side operation timeout, withTransaction can continue to use the
494
513
Changes
495
514
=======
496
515
516
+ :2023-11-22: Document error handling inside the callback.
497
517
:2022-10-05: Remove spec front matter and reformat changelog.
498
518
:2022-01-19: withTransaction applies timeouts per the client-side operations
499
519
timeout specification.
0 commit comments