Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak AsyncConnection.transation to return custom error types #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kylewlacy
Copy link

Currently, AsyncConnection.transaction is hard-coded to only allow a closure that returns an AsyncResult. This PR takes a cue from diesel::Connection.transaction and allows it to return a Result with any error type-- as long as it implements From<diesel::result::Error>.

To implement it, I added a small utility type (TransactionError<E>) that simply wraps an error type, the unwraps it after the transaction completes. We need this so we can go from diesel::result::Error to AsyncError. There may be better ways to solve this, but this was the first solution that came to mind.

I found that allowing any error type made it a lot easier to work with transactions (especially when using anyhow), and this seems like a net-positive from an ergonomics perspective. I'm open to suggestions for other possible improvements for this PR though!

@kylewlacy kylewlacy marked this pull request as ready for review August 10, 2020 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant