Skip to main content

zantetsu_core/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during Zantetsu core operations.
4#[derive(Debug, Error)]
5pub enum ZantetsuError {
6    /// The input string is empty or contains only whitespace.
7    #[error("input is empty or whitespace-only")]
8    EmptyInput,
9
10    /// The parser failed to extract any meaningful metadata.
11    #[error("failed to extract metadata from input: {input:?}")]
12    ParseFailed {
13        /// The input that could not be parsed.
14        input: String,
15    },
16
17    /// A regex pattern failed to compile (should not happen with static patterns).
18    #[error("regex compilation error: {0}")]
19    RegexError(#[from] regex::Error),
20
21    /// The model weights file could not be loaded.
22    #[error("failed to load model: {0}")]
23    ModelLoadError(String),
24
25    /// The model inference failed.
26    #[error("inference error: {0}")]
27    InferenceError(String),
28
29    /// An invalid quality profile was provided.
30    #[error("invalid scoring context: {0}")]
31    InvalidContext(String),
32
33    /// Neural parser error (general parse error string).
34    #[error("neural parser error: {0}")]
35    NeuralParser(String),
36}
37
38/// Result type alias for Zantetsu operations.
39pub type Result<T> = std::result::Result<T, ZantetsuError>;
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn error_display_messages() {
47        let err = ZantetsuError::EmptyInput;
48        assert_eq!(err.to_string(), "input is empty or whitespace-only");
49
50        let err = ZantetsuError::ParseFailed {
51            input: "bad input".into(),
52        };
53        assert!(err.to_string().contains("bad input"));
54    }
55
56    #[test]
57    fn error_is_send_sync() {
58        fn assert_send_sync<T: Send + Sync>() {}
59        assert_send_sync::<ZantetsuError>();
60    }
61}