use thiserror::Error;
#[derive(Debug, Clone)]
pub struct ProcessorConfig {
pub chunk_size: usize,
}
impl Default for ProcessorConfig {
fn default() -> Self {
Self {
chunk_size: 256 * 1024, }
}
}
#[derive(Debug, Error)]
pub enum ProcessingError {
#[error("Text too large for processing: {size} bytes (max: {max} bytes)")]
TextTooLarge { size: usize, max: usize },
#[error("Invalid configuration: {reason}")]
InvalidConfig { reason: String },
#[error("Parallel processing failed")]
ParallelError {
#[source]
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("Invalid UTF-8 in text at position {position}")]
Utf8Error { position: usize },
#[error("Failed to calculate chunk boundaries: {reason}")]
ChunkingError { reason: String },
#[error("Failed to find UTF-8 boundary at position {position}")]
Utf8BoundaryError { position: usize },
#[error("Failed to find word boundary near position {position}")]
WordBoundaryError { position: usize },
#[error("Invalid chunk boundaries: start={start}, end={end}, next={next}")]
InvalidChunkBoundaries {
start: usize,
end: usize,
next: usize,
},
#[error("Memory allocation failed: {reason}")]
AllocationError { reason: String },
#[error("I/O operation failed")]
IoError {
#[from]
source: std::io::Error,
},
#[error("Language rules processing failed: {reason}")]
LanguageRulesError { reason: String },
#[error("Other error: {0}")]
Other(String),
}
pub type ProcessingResult<T> = Result<T, ProcessingError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_config() {
let config = ProcessorConfig::default();
assert_eq!(config.chunk_size, 256 * 1024);
}
#[test]
fn test_error_display() {
let error = ProcessingError::InvalidConfig {
reason: "test reason".to_string(),
};
assert!(error.to_string().contains("test reason"));
}
}