use thiserror::Error;
#[derive(Error, Debug)]
pub enum BatchError {
#[error("Error occurred in the ItemWriter: {0}")]
ItemWriter(String),
#[error("Error occurred in the ItemProcessor: {0}")]
ItemProcessor(String),
#[error("Error occurred in the ItemReader: {0}")]
ItemReader(String),
#[error("Error occurred in the step: {0}")]
Step(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Configuration error: {0}")]
Configuration(String),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_item_writer_error() {
let error = BatchError::ItemWriter("Failed to write item".to_string());
assert_eq!(
error.to_string(),
"Error occurred in the ItemWriter: Failed to write item"
);
}
#[test]
fn test_item_processor_error() {
let error = BatchError::ItemProcessor("Failed to process item".to_string());
assert_eq!(
error.to_string(),
"Error occurred in the ItemProcessor: Failed to process item"
);
}
#[test]
fn test_item_reader_error() {
let error = BatchError::ItemReader("Failed to read item".to_string());
assert_eq!(
error.to_string(),
"Error occurred in the ItemReader: Failed to read item"
);
}
#[test]
fn test_step_error() {
let error = BatchError::Step("Step execution failed".to_string());
assert_eq!(
error.to_string(),
"Error occurred in the step: Step execution failed"
);
}
}