-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
ts: Extract Anchor error codes into their own package #2983
ts: Extract Anchor error codes into their own package #2983
Conversation
@lorisleiva is attempting to deploy a commit to the coral-xyz Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the effort. Are errors the only code that needs to be separated for Anchor to work nicely with web3.js v2, or are there more?
Sorry I missed this question:
Yes, that is everything we need from Anchor for web3.js v2. Since we use Kinobi to generate web3.js v2 compatible clients, all the rest is generated using the Anchor IDL of the program. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is everything we need from Anchor for web3.js v2.
Awesome. We just need the following:
- Add this package to the CI setup action and the setup script
- Note this feature in the CHANGELOG
All done! Let me know if that's all good. 🙏 |
Looks like there was one more workflow to update. We should be good with CI now. 🤞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing the ANCHOR_ERROR__
prefix was added to make the naming consistent with the web3js v2 errors, but I think this kind of naming is redundant for this package since all errors have that prefix. (Not a big deal, just wanted to note this)
Thank you!
This PR extract all Anchor error codes as plain constants into a new granular package named
@coral-xyz/anchor-errors
.This enables anyone to access these constants without having to depend on Anchor's dependencies such as web3.js v1.
For instance, it enables web3.js v2 users to assert that a custom program error is an Anchor error using the following code snippet.
Note that I went for multiple constants instead of an enum for reasons explained here.
Also note that I did not remove the existing
LangErrorCode
object to avoid introducing a breaking change. However, this may be safely dissolved on the next breaking change version.