Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#798
This is pretty rough but I think I need to hurry up and start a PR, oof. I think just about all tests are passing except for
lockup
, which doesn't even build, but I can't seem to find why its registry#[program]
is unhappy.There are two ideas:
First idea: Box up behind a dyn trait the various different error enums that can show up in an anchor program (low-level Solana ProgramErrors, Anchor's framework ErrorCode enum, Anchor's wrapper Error enum, your own custom errors, etc.). In principle it ought to be possible to avoid this dynamic dispatch approach but I'm not sure how to actually do it :/
Second idea/huge hack: Anchor's built-in traits (
Accounts
,AccountsExit
, etc.) all returnProgramResult
s. This means that internal Anchor ErrorCodes get smooshed intoProgramError::Custom(u32)
s, throwing away their messages. I think probably the right fix for this is to change these return types, either toResult<(), crate::error::Error>
, or I don't know, maybe by adding an associatedtype Error: Into<ProgramError>
. I tried the first option. It ends up being a bit of a slog that I never quite managed to finish, and it's a breaking change that requires changing a lot of tests (there are some test ix handlers that rely on auto-into
-ingProgramError
s in functions returningResult<()>
, but that breaks if Anchor traits start usingcrate::error::Error
).So, I thought it was worth starting a PR with something way hackier, based on the original idea I tried: macro generate a mapping from Custom(u32) --> Anchor's ErrorCode enum (we don't need to do this for your own custom
#[error]
enums because you can just use a good return type for your ix handlers, and then the dyn trait stuff handles the rest). This feels so gross but it does seem to work?