Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from semiotic-ai/suchapalaver/fix-error-handling
Browse files Browse the repository at this point in the history
feat: return errors instead of optional field unwrap
  • Loading branch information
suchapalaver authored Sep 14, 2024
2 parents 54971b8 + c9c0c5c commit 03ce720
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ pub mod beacon {
) -> Result<Self, Self::Error> {
Ok(IndexedAttestationBase {
attesting_indices: attesting_indices.into(),
data: data.unwrap().try_into()?,
data: data
.ok_or(ProtosError::NullIndexedAttestationData)?
.try_into()?,
signature: bls::generics::GenericAggregateSignature::deserialize(
signature.as_slice(),
)
Expand Down Expand Up @@ -487,7 +489,9 @@ pub mod beacon {
SignedBeaconBlockHeader { message, signature }: SignedBeaconBlockHeader,
) -> Result<Self, Self::Error> {
Ok(Self {
message: message.unwrap().into(),
message: message
.ok_or(ProtosError::NullSignedBeaconBlockHeaderMessage)?
.into(),
signature: bls::generics::GenericSignature::deserialize(
signature.as_slice(),
)
Expand Down Expand Up @@ -702,6 +706,9 @@ pub enum ProtosError {
#[error("Null attestation data")]
NullAttestationData,

#[error("Null indexed attestation data")]
NullIndexedAttestationData,

#[error("Null block field in block response")]
NullBlock,

Expand All @@ -720,6 +727,9 @@ pub enum ProtosError {
#[error("Proposer Slashing null signer")]
NullSigner,

#[error("Null SignedBeaconBlockHeader Message")]
NullSignedBeaconBlockHeaderMessage,

#[error("Null voluntary exit")]
NullVoluntaryExit,

Expand Down

0 comments on commit 03ce720

Please sign in to comment.