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

[Feature Request] Introduce Typed Errors/Coded Errors #955

Open
Xzirez opened this issue Sep 1, 2022 · 3 comments
Open

[Feature Request] Introduce Typed Errors/Coded Errors #955

Xzirez opened this issue Sep 1, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@Xzirez
Copy link

Xzirez commented Sep 1, 2022

Hello,

I have found that operations involving error handling are pretty cumbersome with the library. For example, when debugging the useDApp library, testing clients written on top of the useDApp library, and showing errors to the user there is no good way for me to organize the possible errors I am given. I can see in the code that the errors returned are not typed or have no specific error codes. This makes it harder especially when testing and showing status codes to the user, as I end up testing against strings or having a collection of possible error codes within an error client.

I feel many of these problems could be made easier if the errors were typed, organized with error codes or had a shared error class. I could be mistaken and there might be somewhere in the code where I can see and handle the errors in a more organized way, but so far i have worked with the library for a couple of weeks and I have not located it yet.

I can see that there was some work very recently on the chainId error handling in this Commit

I will provide more context and some possible examples if necessary. There could be a very good reason why the errors are not typed. If so im happy to get a better understanding :)

Screenshot 2022-08-17 at 15 11 20

Example of error thrown given the wrong chainId.
@Xzirez Xzirez added the enhancement New feature or request label Sep 1, 2022
@Xzirez Xzirez changed the title [Feature Request] Introduce Typed Errors [Feature Request] Introduce Typed Errors/Coded Errors Sep 1, 2022
@rzadp
Copy link
Contributor

rzadp commented Sep 2, 2022

Thanks for this submission.

I agree 100% - typed errors are good and should be utilized as much as possible.

There are however challenges to it - we can't always know what kind of error we have, because we deal with:

  • errors coming from different versions of ethers
  • errors coming from API providers
  • errors coming from different wallets

So the errors are coming in all different formats, causing attempts to interpret them like this:

const errorMessage = e.error?.data?.message ?? e.error?.message ?? e.reason ?? e.data?.message ?? e.message


However, if we can find a way to make sense of it and type errors for some of the cases, and test it with different dependencies, providers and wallets, that would be a good thing.

@Xzirez
Copy link
Author

Xzirez commented Sep 3, 2022

Thank you so much for the insight @rzadp.

I do understand the problem and was also having this issue when testing. If you don't mind I would like to look into if there is a way to handle typed errors for the chainId, as I am currently using this part of the library frequently. If we could unify the error handling of a single service into one format/client first then it would be easy to extend this approach further.

@rzadp
Copy link
Contributor

rzadp commented Sep 12, 2022

If you don't mind I would like to look into if there is a way to handle typed errors for the chainId, as I am currently using this part of the library frequently. If we could unify the error handling of a single service into one format/client first then it would be easy to extend this approach further.

Sounds good, let me know if I can help. We can also chat on discord if faster communication is needed around this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants