Skip to content

Commit dc47fab

Browse files
committed
deprecate DecodeError and stop using it
1 parent 5cd7a9c commit dc47fab

File tree

10 files changed

+6
-69
lines changed

10 files changed

+6
-69
lines changed

Cargo.lock

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

decode-error/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use num_traits::FromPrimitive;
2121
/// [`ProgramError`]: https://docs.rs/solana-program-error/latest/solana_program_error/enum.ProgramError.html
2222
/// [`ProgramError::Custom`]: https://docs.rs/solana-program-error/latest/solana_program_error/enum.ProgramError.html#variant.Custom
2323
/// [`ToPrimitive`]: num_traits::ToPrimitive
24+
#[deprecated(since = "2.3.0", note = "Use `num_traits::FromPrimitive` instead")]
2425
pub trait DecodeError<E> {
2526
fn decode_custom_error_to_enum(custom: u32) -> Option<E>
2627
where
@@ -32,6 +33,7 @@ pub trait DecodeError<E> {
3233
}
3334

3435
#[cfg(test)]
36+
#[allow(deprecated)]
3537
mod tests {
3638
use {super::*, num_derive::FromPrimitive};
3739

precompile-error/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ edition = { workspace = true }
1111

1212
[dependencies]
1313
num-traits = { workspace = true }
14-
solana-decode-error = { workspace = true }
1514

1615
[package.metadata.docs.rs]
1716
targets = ["x86_64-unknown-linux-gnu"]

precompile-error/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// Precompile errors
2-
use {core::fmt, solana_decode_error::DecodeError};
2+
use core::fmt;
33

44
/// Precompile errors
55
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -68,9 +68,3 @@ impl fmt::Display for PrecompileError {
6868
}
6969
}
7070
}
71-
72-
impl<T> DecodeError<T> for PrecompileError {
73-
fn type_of() -> &'static str {
74-
"PrecompileError"
75-
}
76-
}

program-error/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ borsh = { workspace = true, optional = true }
1414
num-traits = { workspace = true }
1515
serde = { workspace = true, optional = true }
1616
serde_derive = { workspace = true, optional = true }
17-
solana-decode-error = { workspace = true }
1817
solana-instruction = { workspace = true, default-features = false, features = [
1918
"std",
2019
] }

program-error/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use serde_derive::{Deserialize, Serialize};
99
use {
1010
core::fmt,
1111
num_traits::FromPrimitive,
12-
solana_decode_error::DecodeError,
1312
solana_instruction::error::{
1413
InstructionError, ACCOUNT_ALREADY_INITIALIZED, ACCOUNT_BORROW_FAILED,
1514
ACCOUNT_DATA_TOO_SMALL, ACCOUNT_NOT_RENT_EXEMPT, ARITHMETIC_OVERFLOW, BORSH_IO_ERROR,
@@ -129,18 +128,18 @@ impl fmt::Display for ProgramError {
129128
pub trait PrintProgramError {
130129
fn print<E>(&self)
131130
where
132-
E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive;
131+
E: 'static + std::error::Error + PrintProgramError + FromPrimitive;
133132
}
134133

135134
#[allow(deprecated)]
136135
impl PrintProgramError for ProgramError {
137136
fn print<E>(&self)
138137
where
139-
E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
138+
E: 'static + std::error::Error + PrintProgramError + FromPrimitive,
140139
{
141140
match self {
142141
Self::Custom(error) => {
143-
if let Some(custom_error) = E::decode_custom_error_to_enum(*error) {
142+
if let Some(custom_error) = E::from_u32(*error) {
144143
custom_error.print::<E>();
145144
} else {
146145
msg!("Error: Unknown");

pubkey/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ rand = { workspace = true, optional = true }
2222
serde = { workspace = true, optional = true }
2323
serde_derive = { workspace = true, optional = true }
2424
solana-atomic-u64 = { workspace = true }
25-
solana-decode-error = { workspace = true }
2625
solana-frozen-abi = { workspace = true, optional = true, features = [
2726
"frozen-abi",
2827
] }

pubkey/src/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use {
2929
str::{from_utf8, FromStr},
3030
},
3131
num_traits::{FromPrimitive, ToPrimitive},
32-
solana_decode_error::DecodeError,
3332
};
3433
#[cfg(target_arch = "wasm32")]
3534
use {
@@ -119,11 +118,6 @@ impl fmt::Display for PubkeyError {
119118
}
120119
}
121120

122-
impl<T> DecodeError<T> for PubkeyError {
123-
fn type_of() -> &'static str {
124-
"PubkeyError"
125-
}
126-
}
127121
impl From<u64> for PubkeyError {
128122
fn from(error: u64) -> Self {
129123
match error {
@@ -378,12 +372,6 @@ impl From<Infallible> for ParsePubkeyError {
378372
}
379373
}
380374

381-
impl<T> DecodeError<T> for ParsePubkeyError {
382-
fn type_of() -> &'static str {
383-
"ParsePubkeyError"
384-
}
385-
}
386-
387375
impl FromStr for Pubkey {
388376
type Err = ParsePubkeyError;
389377

vote-interface/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ num-traits = { workspace = true }
1717
serde = { workspace = true, optional = true }
1818
serde_derive = { workspace = true, optional = true }
1919
solana-clock = { workspace = true }
20-
solana-decode-error = { workspace = true }
2120
solana-frozen-abi = { workspace = true, features = [
2221
"frozen-abi",
2322
], optional = true }

vote-interface/src/error.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use {
44
core::fmt,
55
num_derive::{FromPrimitive, ToPrimitive},
6-
solana_decode_error::DecodeError,
76
};
87

98
/// Reasons the vote might have had an error
@@ -72,40 +71,3 @@ impl fmt::Display for VoteError {
7271
})
7372
}
7473
}
75-
76-
impl<E> DecodeError<E> for VoteError {
77-
fn type_of() -> &'static str {
78-
"VoteError"
79-
}
80-
}
81-
82-
#[cfg(test)]
83-
mod tests {
84-
use {super::*, solana_instruction::error::InstructionError};
85-
86-
#[test]
87-
fn test_custom_error_decode() {
88-
use num_traits::FromPrimitive;
89-
fn pretty_err<T>(err: InstructionError) -> String
90-
where
91-
T: 'static + std::error::Error + DecodeError<T> + FromPrimitive,
92-
{
93-
if let InstructionError::Custom(code) = err {
94-
let specific_error: T = T::decode_custom_error_to_enum(code).unwrap();
95-
format!(
96-
"{:?}: {}::{:?} - {}",
97-
err,
98-
T::type_of(),
99-
specific_error,
100-
specific_error,
101-
)
102-
} else {
103-
"".to_string()
104-
}
105-
}
106-
assert_eq!(
107-
"Custom(0): VoteError::VoteTooOld - vote already recorded or not in slot hashes history",
108-
pretty_err::<VoteError>(VoteError::VoteTooOld.into())
109-
)
110-
}
111-
}

0 commit comments

Comments
 (0)