HENNGE / aiodynamo

Asynchronous, fast, pythonic DynamoDB Client
https://aiodynamo.readthedocs.io/
Other
69 stars 20 forks source link

Implement consistent handling of TransactionCanceled errors. #171

Closed aclemons closed 5 months ago

aclemons commented 6 months ago

Previously, the code handling errors would raise the cause of the cancellation, for example ConditionalCheckFailed or ThrottlingError, if it was caused by the first item in the list of items in the transaction.

If the failure was caused by any other item in the list, the caller would see the TransactionCanceled.

This makes is awkward for calling code to handle errors when interested in the exact item which caused the failure - it needs two except blocks for handling essentially the same thing. One for when it is the first item and another for any other item.

This change removes any special handling and bubbles the TransactionCanceled error up to the caller. I've added a typed value for the cancellation reasons. These are documented here:

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html#API_TransactWriteItems_Errors

This should allow clients to introspect the errors, if needed, with a typed object.

Closes #170

aclemons commented 6 months ago

If we don't like the typed cancellation reasons, I can revert that back out and leave that for library consumers to handle themselves.

aclemons commented 5 months ago

Thanks, I had this on my TODO and let it slip out of focus in the new year. Thanks for tidying up and merging.