-
Notifications
You must be signed in to change notification settings - Fork 846
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
A better way to resolve custom error messages #2019
Comments
Hey Mike, we're working on it for the new Web3.js. Have you seen this? [Copy/pasting the relevant section below]. These create program functions will be generated for each program and will allow us to transform an hex code into an actual program error.
|
Great minds etc! 😃 Thanks @lorisleiva ! Would it be possible to allow |
The That source of information here is being explicitly requested by the function as otherwise we would need a centralised registry of program error codes to fetch from. Is that what you are referring to? P.S.: You might be interested in point [E] of the thread. |
Exactly! Ie if the IDL is published, we fetch the errors from the IDL. If the IDL is not published, we tell this explicitly to the user and return Downsides: we have an HTTP request to resolve the error. Users could turn off custom errors handling if they wanted to to disable this behavior though. Upsides: we have useful errors by default and don't ask users to provide/maintain a list of all the programs they want to use, or have something that recursively gets the programs another program may CPI to per [E] |
Gotcha! I think having an additional asynchronous helper method that uses the Anchor IDL registry for that purpose makes total sense. However, I do think we should keep the synchronous method for situations where we just want to use the information provided by the generated clients to avoid an extra HTTP call that may not even resolve. I'd also like to explore a plugin ecosystem on top of the web3.js library that would help bind all the components together. For instance, this would be much easier to handle with a program repository plugin (which is how Umi handles this problem). |
would it be possible to bubble custom it is less than ideal to have to parse message strings everywhere when implementing error handling. some of them are rpc/sending related, some might be network, some may or may not be program specific. for eg. the custom error class |
We now have first-class try {
// Something.
} catch (e) {
if (isSolanaError(e, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE)) {
// Now TypeScript knows that you have e.context.logs and e.context.returnData and stuff.
// But also…
if (isSolanaError(e.cause, SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM)) {
// Now typescript has e.cause.context.code and e.cause.context.index
}
}
} |
@steveluscher When is it going to be released? I see it's in the technical preview version, but not the stable one. I'd love to use the TP in my project, but I've only found one demo and there's no other examples or documentation. Am I missing something? |
@mlshv Have you checked out this README in the main library? It's a little hidden, but we've kept that up to date. Besides that, some of the packages' READMEs are detailed, and some aren't. Admittedly we don't have end-to-end docs like we'd want to have, but that's mainly because everything has been changing so much. Perhaps Stack Exchange can be a decent medium until then? Also, we have published a "Technology Preview 2", which contains the custom errors, as well as the errors package itself. |
Motivation
A user is using web3.js, making transactions with instructions for the
Token
program. They recieve:Which actually means, per the Token program's errors:
Example use case
This is a frequent show stopper for developers we've seen at Hacker Houses, where someone assumes there's no way to find an actual error. As a short term solution, DevRel added https://github.com/solana-developers/helpers?tab=readme-ov-file#getcustomerrormessage to our helpers library, but the same or better (and hopefully better is possible) solution should be available out of the box.
Details
Worst case: just have something like https://github.com/solana-developers/helpers?tab=readme-ov-file#getcustomerrormessage, code is at https://github.com/solana-developers/helpers/blob/main/src/index.ts#L14
Ideally: web3.js can dynamically fetch the errors for the specific program, and actually resolve the hex code to the real error message from the program as needed.
The text was updated successfully, but these errors were encountered: