Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
node_modules
test-ledger
dist
.idea
15 changes: 14 additions & 1 deletion pod/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Error types
use solana_program_error::{ProgramError, ToStr};
use {
solana_program_error::{ProgramError, ToStr},
std::num::TryFromIntError,
};

/// Errors that may be returned by the spl-pod library.
#[repr(u32)]
Expand All @@ -22,6 +25,9 @@ pub enum PodSliceError {
/// Provided byte buffer too large for expected type
#[error("Provided byte buffer too large for expected type")]
BufferTooLarge,
/// An integer conversion failed because the value was out of range for the target type
#[error("An integer conversion failed because the value was out of range for the target type")]
ValueOutOfRange,
}

impl From<PodSliceError> for ProgramError {
Expand All @@ -36,6 +42,13 @@ impl ToStr for PodSliceError {
PodSliceError::CalculationFailure => "Error in checked math operation",
PodSliceError::BufferTooSmall => "Provided byte buffer too small for expected type",
PodSliceError::BufferTooLarge => "Provided byte buffer too large for expected type",
PodSliceError::ValueOutOfRange => "An integer conversion failed because the value was out of range for the target type"
}
}
}

impl From<TryFromIntError> for PodSliceError {
fn from(_: TryFromIntError) -> Self {
PodSliceError::ValueOutOfRange
}
}
2 changes: 2 additions & 0 deletions pod/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

pub mod bytemuck;
pub mod error;
pub mod list;
pub mod option;
pub mod optional_keys;
pub mod pod_length;
pub mod primitives;
pub mod slice;

Expand Down
Loading