Skip to content

Commit

Permalink
feat: batch error types
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Oct 27, 2024
1 parent f831e15 commit b8bd7c4
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
77 changes: 77 additions & 0 deletions crates/protocol/src/batch/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//! Span Batch Errors

/// Span Batch Errors
#[derive(Debug, derive_more::Display, Clone, PartialEq, Eq)]
pub enum SpanBatchError {
/// The span batch is too big
#[display("The span batch is too big.")]
TooBigSpanBatchSize,
/// The bit field is too long
#[display("The bit field is too long")]
BitfieldTooLong,
/// Empty Span Batch
#[display("Empty span batch")]
EmptySpanBatch,
/// Missing L1 origin
#[display("Missing L1 origin")]
MissingL1Origin,
/// Decoding errors
#[display("Span batch decoding error: {_0}")]
Decoding(SpanDecodingError),
}

impl From<SpanDecodingError> for SpanBatchError {
fn from(err: SpanDecodingError) -> Self {
Self::Decoding(err)
}
}

impl core::error::Error for SpanBatchError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::Decoding(err) => Some(err),
_ => None,
}
}
}

/// Decoding Error
#[derive(Debug, derive_more::Display, Clone, PartialEq, Eq)]
pub enum SpanDecodingError {
/// Failed to decode relative timestamp
#[display("Failed to decode relative timestamp")]
RelativeTimestamp,
/// Failed to decode L1 origin number
#[display("Failed to decode L1 origin number")]
L1OriginNumber,
/// Failed to decode parent check
#[display("Failed to decode parent check")]
ParentCheck,
/// Failed to decode L1 origin check
#[display("Failed to decode L1 origin check")]
L1OriginCheck,
/// Failed to decode block count
#[display("Failed to decode block count")]
BlockCount,
/// Failed to decode block tx counts
#[display("Failed to decode block tx counts")]
BlockTxCounts,
/// Failed to decode transaction nonces
#[display("Failed to decode transaction nonces")]
TxNonces,
/// Mismatch in length between the transaction type and signature arrays in a span batch
/// transaction payload.
#[display("Mismatch in length between the transaction type and signature arrays")]
TypeSignatureLenMismatch,
/// Invalid transaction type
#[display("Invalid transaction type")]
InvalidTransactionType,
/// Invalid transaction data
#[display("Invalid transaction data")]
InvalidTransactionData,
/// Invalid transaction signature
#[display("Invalid transaction signature")]
InvalidTransactionSignature,
}

impl core::error::Error for SpanDecodingError {}
3 changes: 3 additions & 0 deletions crates/protocol/src/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
mod r#type;
pub use r#type::*;

mod errors;
pub use errors::{SpanBatchError, SpanDecodingError};

mod validity;
pub use validity::BatchValidity;

Expand Down
4 changes: 2 additions & 2 deletions crates/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ extern crate alloc;

mod batch;
pub use batch::{
BatchType, BatchValidationProvider, BatchValidity, SingleBatch, SINGLE_BATCH_TYPE,
SPAN_BATCH_TYPE,
BatchType, BatchValidationProvider, BatchValidity, SingleBatch, SpanBatchError,
SpanDecodingError, SINGLE_BATCH_TYPE, SPAN_BATCH_TYPE,
};

mod block;
Expand Down

0 comments on commit b8bd7c4

Please sign in to comment.