Previously, the transaction method of AsyncConnection returned a QueryResult, which propagates the Diesel error type as an error. For a lot of use-cases, this is sufficient, but it prevents transactions from returning "custom errors". Transactions may perform additional operations, in addition to merely DB-oriented operations, so they may have more featureful errors as well.
This PR updates the generic bounds of errors, allowing any error to be propagated from transaction, as long as:
It may be constructed From<DieselError>. After all, the transaction itself may fail, so the returned error needs to be a superset of this type.
It may be constructed From<ConnErr> (aka, the "connection-specific" error type). This is necessary because accessing a connection from the underlying pool and issuing a request may also fail, and must be handled within the transaction type.
The examples are updated to show how a "custom error" may be returned from transactions with this new implementation.
I'll upload the corresponding Omicron change in a sec to demonstrate what this change would look like. TL;DR, more expressive errors can be returned from transactions.
Previously, the
transaction
method ofAsyncConnection
returned aQueryResult
, which propagates the Diesel error type as an error. For a lot of use-cases, this is sufficient, but it prevents transactions from returning "custom errors". Transactions may perform additional operations, in addition to merely DB-oriented operations, so they may have more featureful errors as well.This PR updates the generic bounds of errors, allowing any error to be propagated from
transaction
, as long as:From<DieselError>
. After all, the transaction itself may fail, so the returned error needs to be a superset of this type.From<ConnErr>
(aka, the "connection-specific" error type). This is necessary because accessing a connection from the underlying pool and issuing a request may also fail, and must be handled within thetransaction
type.The examples are updated to show how a "custom error" may be returned from transactions with this new implementation.