batch_mode_batch_reconciliation/
errors.rs

1// ---------------- [ File: batch-mode-batch-reconciliation/src/errors.rs ]
2crate::ix!();
3
4error_tree!{
5
6    pub enum BatchOutputProcessingError {
7        ErrorSavingFailedBatchEntries(ErrorSavingFailedBatchEntries),
8        JsonParseError(JsonParseError),
9        IoError(std::io::Error),
10        SerializationError(serde_json::Error),
11        MissingFilePath,
12    }
13
14    pub enum ErrorSavingFailedBatchEntries {
15        SerdeJsonError(serde_json::Error),
16        IoError(std::io::Error),
17    }
18
19    pub enum BatchReconciliationError {
20        BatchWorkspaceError(BatchWorkspaceError),
21        OpenAIClientError(OpenAIClientError),
22        BatchMetadataError(BatchMetadataError),
23        IOError(std::io::Error),
24        BatchDownloadError(BatchDownloadError),
25        BatchValidationError(BatchValidationError),
26        BatchErrorProcessingError(BatchErrorProcessingError),
27        BatchOutputProcessingError(BatchOutputProcessingError),
28        FileMoveError(FileMoveError),
29
30        #[display("BatchReconciliationError: operation not implemented. operation={operation:?}")]
31        OperationNotImplemented {
32            operation: BatchFileTripleReconciliationOperation,
33        },
34
35        #[display("BatchReconciliationError: reconciliation failed. index={index:?}")]
36        ReconciliationFailed {
37            index:  BatchIndex,
38            //errors: Vec<(BatchFileTripleReconciliationOperation,BatchReconciliationError)>,
39        },
40
41        #[display("BatchReconciliationError: missing input file. index={index:?}, output={output:?}, error={error:?}")]
42        MissingBatchInputFileButOthersExist {
43            index:  BatchIndex,
44            output: Option<PathBuf>,
45            error:  Option<PathBuf>,
46        },
47    }
48
49    pub enum BatchSuccessResponseHandlingError {
50        UuidParseError(UuidParseError),
51        JsonParseError(JsonParseError),
52        SerdeJsonError(serde_json::Error),
53        TokenParseError(TokenParseError),
54        SaveLoadError(SaveLoadError),
55        IoError(std::io::Error),
56    }
57}
58
59impl From<BatchReconciliationError> for MockBatchClientError {
60    fn from(e: BatchReconciliationError) -> Self {
61        MockBatchClientError::BatchReconciliationError { index: e.index().expect("todo: checkme") }
62    }
63}
64
65impl From<BatchOutputProcessingError> for MockBatchClientError {
66    fn from(_e: BatchOutputProcessingError) -> Self {
67        MockBatchClientError::BatchOutputProcessingError
68    }
69}
70
71impl BatchReconciliationError {
72    pub fn index(&self) -> Option<BatchIndex> {
73        match self {
74            BatchReconciliationError::ReconciliationFailed { index } => {
75                Some(index.clone())
76            }
77
78            BatchReconciliationError::MissingBatchInputFileButOthersExist { index, output: _, error: _ } => {
79                Some(index.clone())
80            }
81            _ => None
82        }
83    }
84}