-
Notifications
You must be signed in to change notification settings - Fork 933
[experimental] Convert all thrown errors to SolanaError
#2118
Comments
I want you guys to know I cried when I self-assigned this. |
Thank you @buffalojoec 🫡 I can tackle the errors inside the |
@buffalojoec Actually you might also want to avoid tackling all RPC errors right now as I'm working on a massive refactoring stack. |
You got it, just throw a flag here whenever I'm good to go. |
We can split this up if you want! Want to work from A-Z and I'll work from Z-A @buffalojoec? |
Sure! Are you just basing off of Loris's stack? |
) # Summary Wouldn't it be nice if you could `catch` _particular_ transaction errors in your application, like `BlockhashNotFound`, and choose the correct mitigation based on the type of transaction error? In this PR, we introduce coded exceptions for each `TransactionError` returned from the RPC's `sendTransaction` method. > [!NOTE] > Because the RPC doesn't return structured errors or error codes, we had to break our own rules in this PR and hardcode a map between the error names and the code numbers. My [first crack](https://gist.github.com/steveluscher/aaa7cbbb5433b1197983908a40860c47#file-fml-ts-L12) at this employed a source code compression scheme that I later deemed too risky for the 250 gzipped bytes it saved. We might consider such a scheme in the future, especially since the next PR will add `InstructionError` to the mix. # Test Plan ```shell cd packages/errors pnpm test:unit:browser pnpm test:unit:node ``` Addresses #2118.
# Summary In a future PR when we add `InstructionError` the core mucking code is going to look exactly the same as this. Let's extract it to share with that function, down the line. Addresses #2118.
# Summary In this PR, we build atop the work in #2213 and introduce coded exceptions for each `InstructionError` returned from the RPC's `sendTransaction` method. > [!NOTE] > Because the RPC doesn't return structured errors or error codes, we had to break our own rules in this PR and hardcode a map between the error names and the code numbers. My [first crack](https://gist.github.com/steveluscher/aaa7cbbb5433b1197983908a40860c47#file-fml-ts-L12) at this employed a source code compression scheme that I later deemed too risky for the 250 gzipped bytes it saved. We might consider such a scheme in the future, especially since the next PR will add `InstructionError` to the mix. # Test Plan ```shell cd packages/errors pnpm test:unit:browser pnpm test:unit:node ``` Addresses #2118.
# Summary Invariant violations are a kind of error that should never get hit ever, and if they do your program is broken. In one sense we don't want error codes for them because they're not intended to be caught in downstream programs. On the other hand I've tried to come up with a reason _not_ to give them codes and I can't. Making them a `@solana/error` gives us compression and error decoding for free. Addresses #2118.
🎉 This issue has been resolved in version 1.91.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# Summary So wow. I completely missed these as part of #2118, and it turns out they're a really big deal and required a ton of changes. There are: * Errors that have enough data to format a message * Errors that have no data, but also no context in the message * Errors that have no data, but really should, because you can't format a message without it * Preflight errors in which is nested a `TransactionError` (see #2213) In this PR we create a helper that takes in the `RpcSimulateTransactionResult` from the RPC and reformats it as a coded `SolanaError`. As always, everything you need to know is in the `packages/errors/src/__tests__/json-rpc-error-test.ts`. # Test Plan ``` pnpm turbo test:unit:browser pnpm turbo test:unit:node ```
Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up. |
packages/library-legacy
forthrow new Error
SolanaError
a. Create a code for it in
packages/errors/src/codes.ts
b. Optionally allow the caller to add typed context to the error by defining the type in
packages/errors/src/context.ts
c. Create a message for it in
packages/errors/src/messages.ts
d. Replace the callsite with
throw new SolanaError(SOLANA_ERROR__MY_NEW_ERROR, {/* optional context */})
ProgramErrors
from on-chain programs in the same way (include the logs, message, program address, error code, etc in the error's context)The text was updated successfully, but these errors were encountered: