1use thiserror::Error;
2
3pub type BlobResult<T> = Result<T, BlobError>;
5
6#[derive(Error, Debug)]
8pub enum BlobError {
9 #[error("Blob not found: {id}")]
10 NotFound { id: String },
11
12 #[error("Invalid request: {message}")]
13 Invalid { message: String },
14
15 #[error("Operation not supported by this store")]
16 Unsupported,
17
18 #[error("Upload session not found: {upload_id}")]
19 UploadNotFound { upload_id: String },
20
21 #[error("Upload failed: {reason}")]
22 UploadFailed { reason: String },
23
24 #[error("Storage backend error: {source}")]
25 Backend {
26 #[source]
27 source: Box<dyn std::error::Error + Send + Sync>,
28 },
29
30 #[error("I/O error: {source}")]
31 Io {
32 #[from]
33 source: std::io::Error,
34 },
35
36 #[error("Serialization error: {source}")]
37 Serialization {
38 #[from]
39 source: serde_json::Error,
40 },
41}
42
43impl BlobError {
44 pub fn backend<E>(error: E) -> Self
46 where
47 E: std::error::Error + Send + Sync + 'static,
48 {
49 Self::Backend {
50 source: Box::new(error),
51 }
52 }
53
54 pub fn invalid<S: Into<String>>(message: S) -> Self {
56 Self::Invalid {
57 message: message.into(),
58 }
59 }
60
61 pub fn not_found<S: Into<String>>(id: S) -> Self {
63 Self::NotFound { id: id.into() }
64 }
65
66 pub fn upload_not_found<S: Into<String>>(upload_id: S) -> Self {
68 Self::UploadNotFound {
69 upload_id: upload_id.into(),
70 }
71 }
72
73 pub fn upload_failed<S: Into<String>>(reason: S) -> Self {
75 Self::UploadFailed {
76 reason: reason.into(),
77 }
78 }
79}