use thiserror::Error;
pub type TilesResult<T> = Result<T, TilesError>;
#[derive(Debug, Error)]
pub enum TilesError {
#[error("tile ID {0} out of range (must be 0-255)")]
TileIdOutOfRange(u16),
#[error("delta buffer full for tile {tile_id}, capacity: {capacity}")]
DeltaBufferFull {
tile_id: u8,
capacity: usize,
},
#[error("tile {0} not initialized")]
TileNotInitialized(u8),
#[error("tile {tile_id} in error state: {reason}")]
TileError {
tile_id: u8,
reason: String,
},
#[error("invalid node ID {0} for shard mapping")]
InvalidNodeId(u64),
#[error("witness aggregation failed: {0}")]
WitnessAggregationFailed(String),
#[error("fabric not started")]
FabricNotStarted,
#[error("fabric already running")]
FabricAlreadyRunning,
#[error("coordination error: {0}")]
CoordinationError(String),
#[error("invalid fabric configuration: {0}")]
InvalidConfiguration(String),
#[error("tick {tick_number} processing failed: {reason}")]
TickProcessingFailed {
tick_number: u32,
reason: String,
},
#[error("internal tiles error: {0}")]
Internal(String),
}
impl TilesError {
#[must_use]
pub fn tile_error(tile_id: u8, reason: impl Into<String>) -> Self {
Self::TileError {
tile_id,
reason: reason.into(),
}
}
#[must_use]
pub fn buffer_full(tile_id: u8, capacity: usize) -> Self {
Self::DeltaBufferFull { tile_id, capacity }
}
#[must_use]
pub fn tick_failed(tick_number: u32, reason: impl Into<String>) -> Self {
Self::TickProcessingFailed {
tick_number,
reason: reason.into(),
}
}
}