1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum BatchError {
6 #[error("Error occurred in the ItemWriter: {0}")]
7 ItemWriter(String),
9
10 #[error("Error occurred in the ItemProcessor: {0}")]
11 ItemProcessor(String),
13
14 #[error("Error occurred in the ItemReader: {0}")]
15 ItemReader(String),
17
18 #[error("Error occurred in the step: {0}")]
19 Step(String),
21
22 #[error("IO error: {0}")]
23 Io(#[from] std::io::Error),
25
26 #[error("Configuration error: {0}")]
27 Configuration(String),
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34
35 #[test]
36 fn test_item_writer_error() {
37 let error = BatchError::ItemWriter("Failed to write item".to_string());
38 assert_eq!(
39 error.to_string(),
40 "Error occurred in the ItemWriter: Failed to write item"
41 );
42 }
43
44 #[test]
45 fn test_item_processor_error() {
46 let error = BatchError::ItemProcessor("Failed to process item".to_string());
47 assert_eq!(
48 error.to_string(),
49 "Error occurred in the ItemProcessor: Failed to process item"
50 );
51 }
52
53 #[test]
54 fn test_item_reader_error() {
55 let error = BatchError::ItemReader("Failed to read item".to_string());
56 assert_eq!(
57 error.to_string(),
58 "Error occurred in the ItemReader: Failed to read item"
59 );
60 }
61
62 #[test]
63 fn test_step_error() {
64 let error = BatchError::Step("Step execution failed".to_string());
65 assert_eq!(
66 error.to_string(),
67 "Error occurred in the step: Step execution failed"
68 );
69 }
70}