Skip to content
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

move LamportsError to solana-instruction #3081

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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,
}
}
}
23 changes: 1 addition & 22 deletions sdk/program/src/lamports.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@
//! Defines the [`LamportsError`] type.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the description to read:

//! Re-exports the [`LamportsError`] type for backwards compatibility.


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,
}
}
}
pub use solana_instruction::error::LamportsError;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a deprecated tag here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one was a coinflip for me. I'll add a deprecated tag

Loading