use thiserror::Error;
#[derive(Debug, Error)]
pub enum ZantetsuError {
#[error("input is empty or whitespace-only")]
EmptyInput,
#[error("failed to extract metadata from input: {input:?}")]
ParseFailed {
input: String,
},
#[error("regex compilation error: {0}")]
RegexError(#[from] regex::Error),
#[error("failed to load model: {0}")]
ModelLoadError(String),
#[error("inference error: {0}")]
InferenceError(String),
#[error("invalid scoring context: {0}")]
InvalidContext(String),
#[error("neural parser error: {0}")]
NeuralParser(String),
}
pub type Result<T> = std::result::Result<T, ZantetsuError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn error_display_messages() {
let err = ZantetsuError::EmptyInput;
assert_eq!(err.to_string(), "input is empty or whitespace-only");
let err = ZantetsuError::ParseFailed {
input: "bad input".into(),
};
assert!(err.to_string().contains("bad input"));
}
#[test]
fn error_is_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<ZantetsuError>();
}
}