Skip to content

deprecate DecodeError and stop using it #104

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions decode-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use num_traits::FromPrimitive;
/// [`ProgramError`]: https://docs.rs/solana-program-error/latest/solana_program_error/enum.ProgramError.html
/// [`ProgramError::Custom`]: https://docs.rs/solana-program-error/latest/solana_program_error/enum.ProgramError.html#variant.Custom
/// [`ToPrimitive`]: num_traits::ToPrimitive
#[deprecated(since = "2.3.0", note = "Use `num_traits::FromPrimitive` instead")]
pub trait DecodeError<E> {
fn decode_custom_error_to_enum(custom: u32) -> Option<E>
where
Expand All @@ -32,6 +33,7 @@ pub trait DecodeError<E> {
}

#[cfg(test)]
#[allow(deprecated)]
mod tests {
use {super::*, num_derive::FromPrimitive};

Expand Down
1 change: 0 additions & 1 deletion precompile-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ edition = { workspace = true }

[dependencies]
num-traits = { workspace = true }
solana-decode-error = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
8 changes: 1 addition & 7 deletions precompile-error/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Precompile errors
use {core::fmt, solana_decode_error::DecodeError};
use core::fmt;

/// Precompile errors
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -68,9 +68,3 @@ impl fmt::Display for PrecompileError {
}
}
}

impl<T> DecodeError<T> for PrecompileError {
fn type_of() -> &'static str {
"PrecompileError"
}
}
1 change: 0 additions & 1 deletion program-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ borsh = { workspace = true, optional = true }
num-traits = { workspace = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
solana-decode-error = { workspace = true }
solana-instruction = { workspace = true, default-features = false, features = [
"std",
] }
Expand Down
7 changes: 3 additions & 4 deletions program-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use serde_derive::{Deserialize, Serialize};
use {
core::fmt,
num_traits::FromPrimitive,
solana_decode_error::DecodeError,
solana_instruction::error::{
InstructionError, ACCOUNT_ALREADY_INITIALIZED, ACCOUNT_BORROW_FAILED,
ACCOUNT_DATA_TOO_SMALL, ACCOUNT_NOT_RENT_EXEMPT, ARITHMETIC_OVERFLOW, BORSH_IO_ERROR,
Expand Down Expand Up @@ -129,18 +128,18 @@ impl fmt::Display for ProgramError {
pub trait PrintProgramError {
fn print<E>(&self)
where
E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive;
E: 'static + std::error::Error + PrintProgramError + FromPrimitive;
}

#[allow(deprecated)]
impl PrintProgramError for ProgramError {
fn print<E>(&self)
where
E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
E: 'static + std::error::Error + PrintProgramError + FromPrimitive,
{
match self {
Self::Custom(error) => {
if let Some(custom_error) = E::decode_custom_error_to_enum(*error) {
if let Some(custom_error) = E::from_u32(*error) {
custom_error.print::<E>();
} else {
msg!("Error: Unknown");
Expand Down
1 change: 0 additions & 1 deletion pubkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ rand = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
solana-atomic-u64 = { workspace = true }
solana-decode-error = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true, features = [
"frozen-abi",
] }
Expand Down
12 changes: 0 additions & 12 deletions pubkey/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use {
str::{from_utf8, FromStr},
},
num_traits::{FromPrimitive, ToPrimitive},
solana_decode_error::DecodeError,
};
#[cfg(target_arch = "wasm32")]
use {
Expand Down Expand Up @@ -119,11 +118,6 @@ impl fmt::Display for PubkeyError {
}
}

impl<T> DecodeError<T> for PubkeyError {
fn type_of() -> &'static str {
"PubkeyError"
}
}
impl From<u64> for PubkeyError {
fn from(error: u64) -> Self {
match error {
Expand Down Expand Up @@ -378,12 +372,6 @@ impl From<Infallible> for ParsePubkeyError {
}
}

impl<T> DecodeError<T> for ParsePubkeyError {
fn type_of() -> &'static str {
"ParsePubkeyError"
}
}

impl FromStr for Pubkey {
type Err = ParsePubkeyError;

Expand Down
1 change: 0 additions & 1 deletion vote-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ num-traits = { workspace = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
solana-clock = { workspace = true }
solana-decode-error = { workspace = true }
solana-frozen-abi = { workspace = true, features = [
"frozen-abi",
], optional = true }
Expand Down
38 changes: 0 additions & 38 deletions vote-interface/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use {
core::fmt,
num_derive::{FromPrimitive, ToPrimitive},
solana_decode_error::DecodeError,
};

/// Reasons the vote might have had an error
Expand Down Expand Up @@ -72,40 +71,3 @@ impl fmt::Display for VoteError {
})
}
}

impl<E> DecodeError<E> for VoteError {
fn type_of() -> &'static str {
"VoteError"
}
}

#[cfg(test)]
mod tests {
use {super::*, solana_instruction::error::InstructionError};

#[test]
fn test_custom_error_decode() {
use num_traits::FromPrimitive;
fn pretty_err<T>(err: InstructionError) -> String
where
T: 'static + std::error::Error + DecodeError<T> + FromPrimitive,
{
if let InstructionError::Custom(code) = err {
let specific_error: T = T::decode_custom_error_to_enum(code).unwrap();
format!(
"{:?}: {}::{:?} - {}",
err,
T::type_of(),
specific_error,
specific_error,
)
} else {
"".to_string()
}
}
assert_eq!(
"Custom(0): VoteError::VoteTooOld - vote already recorded or not in slot hashes history",
pretty_err::<VoteError>(VoteError::VoteTooOld.into())
)
}
}