use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum PartialError {
#[error("partial wire format rejected: {kind}")]
Format {
kind: PartialFormatErrorKind,
},
#[error("partial dataset_hash mismatch: expected {expected:02x?}, got {actual:02x?}")]
DatasetMismatch {
expected: [u8; 32],
actual: [u8; 32],
},
#[error("partial params_hash mismatch: expected {expected:02x?}, got {actual:02x?}")]
ParamsMismatch {
expected: [u8; 32],
actual: [u8; 32],
},
#[error("partials cover image_id={image_id} on both rank {rank_a} and rank {rank_b}")]
PartitionOverlap {
rank_a: u32,
rank_b: u32,
image_id: i64,
},
#[error("partials share rank_id={rank_id} in strict mode")]
RankCollision {
rank_id: u32,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum PartialFormatErrorKind {
#[error("partial too short: observed {observed} bytes, minimum {minimum}")]
TooShort {
observed: usize,
minimum: usize,
},
#[error("wrong magic bytes: expected \"VRPS\", got {found:02x?}")]
WrongMagic {
found: [u8; 4],
},
#[error("wrong format_version: expected {expected}, got {found}")]
WrongVersion {
expected: u8,
found: u8,
},
#[error("crc32 footer mismatch")]
Crc,
#[error("paradigm_kind mismatch: expected {expected}, got {found}")]
ParadigmMismatch {
expected: u8,
found: u8,
},
#[error("kernel_kind mismatch: expected discriminant {expected}, got {found}")]
KernelMismatch {
expected: u32,
found: u32,
},
#[error("shape fingerprint mismatch: {detail}")]
GridMismatch {
detail: String,
},
#[error("parity_mode mismatch: expected discriminant {expected}, got {found}")]
ParityMismatch {
expected: u8,
found: u8,
},
#[error("rkyv archive validation failed: {detail}")]
RkyvDecode {
detail: String,
},
#[error("partial wire-format internal error: {detail}")]
Internal {
detail: String,
},
}
impl PartialFormatErrorKind {
pub fn tag(&self) -> &'static str {
match self {
Self::TooShort { .. } => "too_short",
Self::WrongMagic { .. } => "wrong_magic",
Self::WrongVersion { .. } => "wrong_version",
Self::Crc => "crc",
Self::ParadigmMismatch { .. } => "paradigm_mismatch",
Self::KernelMismatch { .. } => "kernel_mismatch",
Self::GridMismatch { .. } => "grid_mismatch",
Self::ParityMismatch { .. } => "parity_mismatch",
Self::RkyvDecode { .. } => "rkyv_decode",
Self::Internal { .. } => "internal",
}
}
}