oxidecomputer / async-bb8-diesel

Safe asynchronous access to Diesel and the bb8 connection manager
MIT License
12 stars 8 forks source link

Use generic errors in transactions #9

Closed smklein closed 2 years ago

smklein commented 2 years ago

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:

  1. 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.
  2. 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.

smklein commented 2 years ago

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.