Skip to content

Commit

Permalink
move LamportsError to solana-instruction (#3081)
Browse files Browse the repository at this point in the history
* move LamportsError to solana-instruction

* nits
  • Loading branch information
kevinheavey authored Oct 9, 2024
1 parent 74f6634 commit d663e05
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
29 changes: 29 additions & 0 deletions sdk/instruction/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,32 @@ where
}
}
}

#[derive(Debug)]
pub enum LamportsError {
/// arithmetic underflowed
ArithmeticUnderflow,
/// arithmetic overflowed
ArithmeticOverflow,
}

#[cfg(feature = "std")]
impl std::error::Error for LamportsError {}

impl fmt::Display for LamportsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::ArithmeticUnderflow => f.write_str("Arithmetic underflowed"),
Self::ArithmeticOverflow => f.write_str("Arithmetic overflowed"),
}
}
}

impl From<LamportsError> for InstructionError {
fn from(error: LamportsError) -> Self {
match error {
LamportsError::ArithmeticOverflow => InstructionError::ArithmeticOverflow,
LamportsError::ArithmeticUnderflow => InstructionError::ArithmeticOverflow,
}
}
}
29 changes: 6 additions & 23 deletions sdk/program/src/lamports.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
//! Defines the [`LamportsError`] type.
use {crate::instruction::InstructionError, thiserror::Error};

#[derive(Debug, Error)]
pub enum LamportsError {
/// arithmetic underflowed
#[error("Arithmetic underflowed")]
ArithmeticUnderflow,

/// arithmetic overflowed
#[error("Arithmetic overflowed")]
ArithmeticOverflow,
}

impl From<LamportsError> for InstructionError {
fn from(error: LamportsError) -> Self {
match error {
LamportsError::ArithmeticOverflow => InstructionError::ArithmeticOverflow,
LamportsError::ArithmeticUnderflow => InstructionError::ArithmeticOverflow,
}
}
}
//! Re-exports the [`LamportsError`] type for backwards compatibility.
#[deprecated(
since = "2.1.0",
note = "Use solana_instruction::error::LamportsError instead"
)]
pub use solana_instruction::error::LamportsError;

0 comments on commit d663e05

Please sign in to comment.