Skip to main content

crackle_runtime/
error.rs

1use std::fmt;
2#[cfg(feature = "serde")]
3use serde::{Serialize, Deserialize};
4
5/// Errors that can occur during crackle runtime operations.
6#[derive(Debug)]
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8pub enum CrackleError {
9    /// A task panicked during firing.
10    TaskPanicked(String),
11    /// The kiln was already cooled and cannot accept new tasks.
12    KilnCooled,
13    /// Invalid thermal profile configuration.
14    InvalidProfile(String),
15    /// Pattern detection failed.
16    DetectionFailed(String),
17}
18
19impl fmt::Display for CrackleError {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            CrackleError::TaskPanicked(msg) => write!(f, "task panicked: {msg}"),
23            CrackleError::KilnCooled => write!(f, "kiln has already cooled and cannot accept new tasks"),
24            CrackleError::InvalidProfile(msg) => write!(f, "invalid thermal profile: {msg}"),
25            CrackleError::DetectionFailed(msg) => write!(f, "pattern detection failed: {msg}"),
26        }
27    }
28}
29
30impl std::error::Error for CrackleError {}
31
32/// A specialized result type for crackle runtime operations.
33pub type Result<T> = std::result::Result<T, CrackleError>;