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

chore: fix async raises warnings #100

Merged
merged 3 commits into from
Dec 9, 2024
Merged

chore: fix async raises warnings #100

merged 3 commits into from
Dec 9, 2024

Conversation

AuHau
Copy link
Member

@AuHau AuHau commented Dec 4, 2024

No description provided.

Copy link

@dryajov dryajov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to rethink how we're handling this. Can you describe what the actual issue is?

body
except CancelledError as error:
raise error
except CatchableError as error:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we blindly converting any exception into a SubscriptionError, this obfuscates the actual error.

Copy link
Member Author

@AuHau AuHau Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just wrapping it, so it does not obfuscate it, you will get the original stack error if you ask for it. This is because json_rpc (eq. any eth_* calls) can throw CatchableError.

I just wanted to remove some warnings around async raises, I am happy to simply remove those completely 🤷‍♂️ Or do whatever you want, I just don't want to spend any big time on this, please.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to remove some warnings around async raises

What you're doing is hiding a potential underlying problem, not properly fixing it.

I was taking a closer look at the code and I'm not even sure where toErr comes from and what does it do. Do you?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you?

Yes, it is coming from here

proc toErr*[E1: ref CatchableError, E2: EthersError](
and as I said it wraps the error not "discards" it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a way to "unify" the error coming from this module (Subscription) in order to communicate that these errors might come from this module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dryajov I agree it's good not to overuse something like this, however calls to these RPC endpoints result in a generic JsonRpcError error regardless of what the error is. Other than RPC calls, there are very few exception raising paths. So this template is convenient for converting these errors to a module-level error.

@AuHau could you catch JsonRpcError specifically (instead of CatchableError) and see if it doesn't leak any other errors? There might be a KeyError here or there that could be caught separately, but I don't see it as really being of much benefit.

Copy link
Member Author

@AuHau AuHau Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I change the CatchableError to JsonRpcError, the compiler will complain with this:

.../nim-ethers/ethers/providers/jsonrpc/subscriptions.nim(123, 40) Error: cast[type(eth_subscribe(subscriptions.client, "newHeads"))](chronosInternalRetFuture.internalChild).internalError can raise an unlisted exception: ref CatchableError

So this confirms what I was saying earlier - any RPC's eth_* call we have will raise CatchableError and that is what we need to work with. So I see 4 approaches:

  1. We add CatchableError to the async raises.
  2. We at least wrap it to SubscriptionError and raise that.
  3. We remove raises all together.
  4. We do nothing.

I can't think of anything else. So @dryajov please pick. My favorite is the current approach - number 2.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see that we're wrapping the underlying error, that is good enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we discussed this already, but just for posterity, it seems that the compiler always reports that a CatchableError is leaking, and never reports the derived type. As an example, there could be a KeyError being leaked, which is derived from CatchableError, but the compiler will still report that a CatchableError is leaking.

Copy link
Contributor

@emizzle emizzle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thanks for doing this! I don't want to drag out this PR too much, but would be nice to see unsubscribe not raise any exceptions.

Comment on lines 148 to 150
convertErrorsToSubscriptionError:
subscriptions.callbacks.del(id)
discard await subscriptions.client.eth_unsubscribe(id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should raise [] from this proc, since we don't really care if unsubscribing fails. This will require a change to the base method as well, but the PollingSubscriptions override should mostly be handled already -- see #98 (comment) for some context.

body
except CancelledError as error:
raise error
except CatchableError as error:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dryajov I agree it's good not to overuse something like this, however calls to these RPC endpoints result in a generic JsonRpcError error regardless of what the error is. Other than RPC calls, there are very few exception raising paths. So this template is convenient for converting these errors to a module-level error.

@AuHau could you catch JsonRpcError specifically (instead of CatchableError) and see if it doesn't leak any other errors? There might be a KeyError here or there that could be caught separately, but I don't see it as really being of much benefit.

Copy link

@dryajov dryajov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AuHau AuHau merged commit 037bef0 into main Dec 9, 2024
3 checks passed
@AuHau AuHau deleted the chore/fix-warnings branch December 9, 2024 15:22
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.

3 participants