kona_derive/errors/
sources.rsuse super::{PipelineError, PipelineErrorKind};
use alloc::string::{String, ToString};
#[derive(derive_more::Display, Debug, PartialEq, Eq)]
pub enum BlobDecodingError {
#[display("Invalid field element")]
InvalidFieldElement,
#[display("Invalid encoding version")]
InvalidEncodingVersion,
#[display("Invalid length")]
InvalidLength,
#[display("Missing data")]
MissingData,
}
impl core::error::Error for BlobDecodingError {}
#[derive(derive_more::Display, Debug, PartialEq, Eq)]
pub enum BlobProviderError {
#[display("Blob sidecar length mismatch: expected {_0}, got {_1}")]
SidecarLengthMismatch(usize, usize),
#[display("Failed to derive slot")]
SlotDerivation,
#[display("Blob decoding error: {_0}")]
BlobDecoding(BlobDecodingError),
#[display("{_0}")]
Backend(String),
}
impl From<BlobProviderError> for PipelineErrorKind {
fn from(val: BlobProviderError) -> Self {
match val {
BlobProviderError::SidecarLengthMismatch(_, _) => {
PipelineError::Provider(val.to_string()).crit()
}
BlobProviderError::SlotDerivation => PipelineError::Provider(val.to_string()).crit(),
BlobProviderError::BlobDecoding(_) => PipelineError::Provider(val.to_string()).crit(),
BlobProviderError::Backend(_) => PipelineError::Provider(val.to_string()).temp(),
}
}
}
impl From<BlobDecodingError> for BlobProviderError {
fn from(err: BlobDecodingError) -> Self {
Self::BlobDecoding(err)
}
}
impl core::error::Error for BlobProviderError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::BlobDecoding(err) => Some(err),
_ => None,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use core::error::Error;
#[test]
fn test_blob_decoding_error_source() {
let err: BlobProviderError = BlobDecodingError::InvalidFieldElement.into();
assert!(err.source().is_some());
}
#[test]
fn test_from_blob_provider_error() {
let err: PipelineErrorKind = BlobProviderError::SlotDerivation.into();
assert!(matches!(err, PipelineErrorKind::Critical(_)));
let err: PipelineErrorKind = BlobProviderError::SidecarLengthMismatch(1, 2).into();
assert!(matches!(err, PipelineErrorKind::Critical(_)));
let err: PipelineErrorKind =
BlobProviderError::BlobDecoding(BlobDecodingError::InvalidFieldElement).into();
assert!(matches!(err, PipelineErrorKind::Critical(_)));
}
}