Skip to main content

xet_data/file_reconstruction/
error.rs

1use std::sync::Arc;
2
3use thiserror::Error;
4
5/// Errors that can occur during file reconstruction.
6#[non_exhaustive]
7#[derive(Error, Debug, Clone)]
8pub enum FileReconstructionError {
9    #[error("CAS Client Error: {0}")]
10    ClientError(Arc<xet_client::ClientError>),
11
12    #[error("IO Error: {0}")]
13    IoError(Arc<std::io::Error>),
14
15    #[error("Task Runtime Error: {0}")]
16    TaskRuntimeError(Arc<xet_runtime::utils::RwTaskLockError>),
17
18    #[error("Corrupted Reconstruction: {0}")]
19    CorruptedReconstruction(String),
20
21    #[error("Configuration Error: {0}")]
22    ConfigurationError(String),
23
24    #[error("Internal Writer Error: {0}")]
25    InternalWriterError(String),
26
27    #[error("Internal Error: {0}")]
28    InternalError(String),
29
30    #[error("Task Join Error: {0}")]
31    TaskJoinError(Arc<tokio::task::JoinError>),
32
33    #[cfg(target_family = "wasm")]
34    #[error("Task Join Error (wasm): {0}")]
35    WasmTaskJoinError(Arc<tokio_with_wasm::task::JoinError>),
36
37    #[error("Runtime Error: {0}")]
38    RuntimeError(Arc<xet_runtime::RuntimeError>),
39}
40
41pub type Result<T> = std::result::Result<T, FileReconstructionError>;
42
43impl From<std::io::Error> for FileReconstructionError {
44    fn from(err: std::io::Error) -> Self {
45        FileReconstructionError::IoError(Arc::new(err))
46    }
47}
48
49impl From<xet_client::ClientError> for FileReconstructionError {
50    fn from(err: xet_client::ClientError) -> Self {
51        FileReconstructionError::ClientError(Arc::new(err))
52    }
53}
54
55impl From<xet_runtime::utils::RwTaskLockError> for FileReconstructionError {
56    fn from(err: xet_runtime::utils::RwTaskLockError) -> Self {
57        FileReconstructionError::TaskRuntimeError(Arc::new(err))
58    }
59}
60
61impl From<tokio::task::JoinError> for FileReconstructionError {
62    fn from(err: tokio::task::JoinError) -> Self {
63        FileReconstructionError::TaskJoinError(Arc::new(err))
64    }
65}
66
67#[cfg(target_family = "wasm")]
68impl From<tokio_with_wasm::task::JoinError> for FileReconstructionError {
69    fn from(err: tokio_with_wasm::task::JoinError) -> Self {
70        FileReconstructionError::WasmTaskJoinError(Arc::new(err))
71    }
72}
73
74impl From<xet_runtime::RuntimeError> for FileReconstructionError {
75    fn from(err: xet_runtime::RuntimeError) -> Self {
76        FileReconstructionError::RuntimeError(Arc::new(err))
77    }
78}