1use std::string::FromUtf8Error;
2use std::sync::mpsc::RecvError;
3
4use thiserror::Error;
5use tokio::sync::AcquireError;
6use tracing::error;
7use xet_client::ClientError;
8use xet_client::cas_client::auth::AuthError;
9use xet_core_structures::CoreError;
10use xet_core_structures::merklehash::DataHashHexParseError;
11use xet_runtime::RuntimeError;
12use xet_runtime::core::par_utils::ParutilsError;
13use xet_runtime::utils::errors::SingleflightError;
14
15#[cfg(not(target_family = "wasm"))]
16use crate::file_reconstruction::FileReconstructionError;
17
18#[derive(Error, Debug)]
19pub enum DataError {
20 #[error("File query policy configuration error: {0}")]
21 FileQueryPolicyError(String),
22
23 #[error("CAS configuration error: {0}")]
24 CASConfigError(String),
25
26 #[error("Shard configuration error: {0}")]
27 ShardConfigError(String),
28
29 #[error("Deduplication configuration error: {0}")]
30 DedupConfigError(String),
31
32 #[error("Clean task error: {0}")]
33 CleanTaskError(String),
34
35 #[error("Upload task error: {0}")]
36 UploadTaskError(String),
37
38 #[error("Internal error: {0}")]
39 InternalError(String),
40
41 #[error("Synchronization error: {0}")]
42 SyncError(String),
43
44 #[error("Channel error: {0}")]
45 ChannelRecvError(#[from] RecvError),
46
47 #[error("Core structures error: {0}")]
48 FormatError(#[from] CoreError),
49
50 #[error("Client error: {0}")]
51 ClientError(#[from] ClientError),
52
53 #[error("Subtask scheduling error: {0}")]
54 JoinError(#[from] tokio::task::JoinError),
55
56 #[error("Non-small file not cleaned: {0}")]
57 FileNotCleanedError(#[from] FromUtf8Error),
58
59 #[error("I/O error: {0}")]
60 IOError(#[from] std::io::Error),
61
62 #[error("Hash not found")]
63 HashNotFound,
64
65 #[error("Parameter error: {0}")]
66 ParameterError(String),
67
68 #[error("Unable to parse string as hex hash value")]
69 HashStringParsingFailure(#[from] DataHashHexParseError),
70
71 #[error("Deprecated feature: {0}")]
72 DeprecatedError(String),
73
74 #[error("Invalid operation: {0}")]
75 InvalidOperation(String),
76
77 #[error("File size mismatch: expected {expected} bytes but downloaded {actual} bytes")]
78 SizeMismatch { expected: u64, actual: u64 },
79 #[error("Auth error: {0}")]
80 AuthError(#[from] AuthError),
81
82 #[error("Permit acquisition error: {0}")]
83 PermitAcquisitionError(#[from] AcquireError),
84
85 #[cfg(not(target_family = "wasm"))]
86 #[error("File reconstruction error: {0}")]
87 FileReconstructionError(#[from] FileReconstructionError),
88
89 #[error("Runtime error: {0}")]
90 RuntimeError(#[from] RuntimeError),
91}
92
93pub type Result<T> = std::result::Result<T, DataError>;
94
95impl From<SingleflightError<DataError>> for DataError {
96 fn from(value: SingleflightError<DataError>) -> Self {
97 let msg = format!("{value:?}");
98 error!("{msg}");
99 match value {
100 SingleflightError::InternalError(e) => e,
101 _ => DataError::InternalError(format!("SingleflightError: {msg}")),
102 }
103 }
104}
105
106impl From<ParutilsError<DataError>> for DataError {
107 fn from(value: ParutilsError<DataError>) -> Self {
108 match value {
109 ParutilsError::Join(e) => DataError::JoinError(e),
110 ParutilsError::Acquire(e) => DataError::PermitAcquisitionError(e),
111 ParutilsError::Task(e) => e,
112 e => DataError::InternalError(e.to_string()),
113 }
114 }
115}