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