1use thiserror::Error;
2
3#[derive(Debug, Error)]
5pub enum ZantetsuError {
6 #[error("input is empty or whitespace-only")]
8 EmptyInput,
9
10 #[error("failed to extract metadata from input: {input:?}")]
12 ParseFailed {
13 input: String,
15 },
16
17 #[error("regex compilation error: {0}")]
19 RegexError(#[from] regex::Error),
20
21 #[error("failed to load model: {0}")]
23 ModelLoadError(String),
24
25 #[error("inference error: {0}")]
27 InferenceError(String),
28
29 #[error("invalid scoring context: {0}")]
31 InvalidContext(String),
32
33 #[error("neural parser error: {0}")]
35 NeuralParser(String),
36}
37
38pub 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}