-
Notifications
You must be signed in to change notification settings - Fork 17
program-error: Remove solana-program usage #51
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,9 @@ | |
|
|
||
| Macros for implementing error-based traits on enums. | ||
|
|
||
| - `#[derive(IntoProgramError)]`: automatically derives the trait `From<Self> for solana_program::program_error::ProgramError`. | ||
| - `#[derive(DecodeError)]`: automatically derives the trait `solana_program::decode_error::DecodeError<T>`. | ||
| - `#[derive(PrintProgramError)]`: automatically derives the trait `solana_program::program_error::PrintProgramError`. | ||
| - `#[derive(IntoProgramError)]`: automatically derives the trait `From<Self> for solana_program_error::ProgramError`. | ||
| - `#[derive(DecodeError)]`: automatically derives the trait `solana_decode_error::DecodeError<T>`. | ||
| - `#[derive(PrintProgramError)]`: automatically derives the trait `solana_program_error::PrintProgramError`. | ||
| - `#[spl_program_error]`: Automatically derives all below traits: | ||
| - `Clone` | ||
| - `Debug` | ||
|
|
@@ -18,7 +18,7 @@ Macros for implementing error-based traits on enums. | |
|
|
||
| ### `#[derive(IntoProgramError)]` | ||
|
|
||
| This derive macro automatically derives the trait `From<Self> for solana_program::program_error::ProgramError`. | ||
| This derive macro automatically derives the trait `From<Self> for solana_program_error::ProgramError`. | ||
|
|
||
| Your enum must implement the following traits in order for this macro to work: | ||
|
|
||
|
|
@@ -48,7 +48,7 @@ pub enum ExampleError { | |
|
|
||
| ### `#[derive(DecodeError)]` | ||
|
|
||
| This derive macro automatically derives the trait `solana_program::decode_error::DecodeError<T>`. | ||
| This derive macro automatically derives the trait `solana_decode_error::DecodeError<T>`. | ||
|
|
||
| Your enum must implement the following traits in order for this macro to work: | ||
|
|
||
|
|
@@ -86,7 +86,7 @@ pub enum ExampleError { | |
|
|
||
| ### `#[derive(PrintProgramError)]` | ||
|
|
||
| This derive macro automatically derives the trait `solana_program::program_error::PrintProgramError`. | ||
| This derive macro automatically derives the trait `solana_program_error::PrintProgramError`. | ||
|
|
||
| Your enum must implement the following traits in order for this macro to work: | ||
|
|
||
|
|
@@ -149,10 +149,10 @@ It also imports the required crates so you don't have to in your program: | |
| Just annotate your enum... | ||
|
|
||
| ```rust | ||
| use solana_program_error_derive::*; | ||
| use spl_program_error_derive::*; | ||
|
|
||
| /// Example error | ||
| #[solana_program_error] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha whoops. Thanks! |
||
| #[spl_program_error] | ||
| pub enum ExampleError { | ||
| /// Mint has no mint authority | ||
| #[error("Mint has no mint authority")] | ||
|
|
@@ -261,29 +261,29 @@ impl ::core::cmp::PartialEq for ExampleError { | |
| __self_tag == __arg1_tag | ||
| } | ||
| } | ||
| impl From<ExampleError> for solana_program::program_error::ProgramError { | ||
| impl From<ExampleError> for solana_program_error::ProgramError { | ||
| fn from(e: ExampleError) -> Self { | ||
| solana_program::program_error::ProgramError::Custom(e as u32) | ||
| solana_program_error::ProgramError::Custom(e as u32) | ||
| } | ||
| } | ||
| impl<T> solana_program::decode_error::DecodeError<T> for ExampleError { | ||
| impl<T> solana_decode_error::DecodeError<T> for ExampleError { | ||
| fn type_of() -> &'static str { | ||
| "ExampleError" | ||
| } | ||
| } | ||
| impl solana_program::program_error::PrintProgramError for ExampleError { | ||
| impl solana_program_error::PrintProgramError for ExampleError { | ||
| fn print<E>(&self) | ||
| where | ||
| E: 'static + std::error::Error + solana_program::decode_error::DecodeError<E> | ||
| + solana_program::program_error::PrintProgramError | ||
| E: 'static + std::error::Error + solana_decode_error::DecodeError<E> | ||
| + solana_program_error::PrintProgramError | ||
| + num_traits::FromPrimitive, | ||
| { | ||
| match self { | ||
| ExampleError::MintHasNoMintAuthority => { | ||
| ::solana_program::log::sol_log("Mint has no mint authority") | ||
| ::solana_msg::sol_log("Mint has no mint authority") | ||
| } | ||
| ExampleError::IncorrectMintAuthority => { | ||
| ::solana_program::log::sol_log( | ||
| ::solana_msg::sol_log( | ||
| "Incorrect mint authority has signed the instruction", | ||
| ) | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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.
This is actually almost a leaf dependency. It depends on
solana-define-syscall, which is a leaf.So, this should work for all versions past 2.2.1 for 2.2 SDK crates. It's 2.3 where we'll see how it behaves, and if we do semver right in the SDK repo, we should be good!
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.
Hehe I did think about doing that -- we could even just redefine the syscall directly in this crate 😈