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

checked exceptions in stores #1179

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

marcinczenko
Copy link
Contributor

@marcinczenko marcinczenko commented Mar 29, 2025

While working on BitTorrent stuff and trying to keep exceptions checked, I continuously hit the wall of set of "stores" which mostly do not use anything but .async..

This PR adds checked exceptions to all stores and dependent abstractions.

To keep the PR still maintainable it focuses on the "stores", thus it has pretty much a minimal set of changes to get them compile.

Most of the changes are easy and syntactical, but there were a few exceptions where it was a big pain to move forward.
It all boils down to AsynIter, most probably created before async: (raises: [CancelledError]) era, that makes checking exceptions much harder where it is used.

The only way to get it clean was for me to create a version of AsyncIter (called SafeAsyncIter) that uses Results and only ever allows for async: (raises: [CancelledError]). I applied it to listBlocks and getBlockExpirations and doing this I could remove problematic situations (especially in block maintenance). SafeAsynIter has the same API as AsynIter and requires very little work (pretty much syntactical) to use it in place of AsyncIter, which is still used in some other places, which can be dealt with in a separate PR to keep this one small.

To get some insights about challenges that you may encounter when working with checked (raising) exception, you may like to check the following note: https://publish.obsidian.md/bittorrent/10+Notes/Async+checked+(raising)+exceptions.

@marcinczenko marcinczenko force-pushed the checked-exceptions-in-stores branch 2 times, most recently from dd3b320 to a1b3846 Compare March 30, 2025 19:43
@marcinczenko marcinczenko marked this pull request as ready for review March 30, 2025 21:27
@marcinczenko marcinczenko requested review from gmega, dryajov and markspanbroek and removed request for gmega March 30, 2025 21:28
@marcinczenko marcinczenko self-assigned this Mar 30, 2025
@marcinczenko marcinczenko force-pushed the checked-exceptions-in-stores branch 2 times, most recently from 91770af to 1694a76 Compare March 31, 2025 18:03
@marcinczenko marcinczenko force-pushed the checked-exceptions-in-stores branch from 1694a76 to 4d74fff Compare March 31, 2025 18:39
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.

2 participants