1use std::io;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
8pub enum Error {
9 #[error("File not found: {0}")]
11 NotFound(String),
12
13 #[error("Permission denied: {0}")]
15 PermissionDenied(String),
16
17 #[error("IO error: {0}")]
19 Io(#[from] io::Error),
20
21 #[error("Invalid path: {0}")]
23 InvalidPath(String),
24
25 #[error("Disk not configured: {0}")]
27 DiskNotConfigured(String),
28
29 #[cfg(feature = "s3")]
31 #[error("S3 error: {0}")]
32 S3(String),
33
34 #[error("Not implemented: {0}")]
36 NotImplemented(String),
37
38 #[error("Serialization error: {0}")]
40 Serialization(String),
41
42 #[error("CDN error: {0}")]
44 Cdn(String),
45
46 #[error("CDN_PROVIDER value '{0}' is not valid; valid values: none, digitalocean, bunny, cloudflare")]
48 CdnInvalidProvider(String),
49
50 #[error("CDN_PROVIDER={0} requires the '{1}' cargo feature")]
52 CdnFeatureRequired(String, &'static str),
53}
54
55impl Error {
56 pub fn not_found(path: impl Into<String>) -> Self {
58 Self::NotFound(path.into())
59 }
60
61 pub fn permission_denied(msg: impl Into<String>) -> Self {
63 Self::PermissionDenied(msg.into())
64 }
65
66 pub fn invalid_path(path: impl Into<String>) -> Self {
68 Self::InvalidPath(path.into())
69 }
70
71 pub fn disk_not_configured(disk: impl Into<String>) -> Self {
73 Self::DiskNotConfigured(disk.into())
74 }
75
76 pub fn not_implemented(feature: impl Into<String>) -> Self {
78 Self::NotImplemented(feature.into())
79 }
80
81 pub fn cdn(msg: impl Into<String>) -> Self {
83 Self::Cdn(msg.into())
84 }
85
86 pub fn cdn_invalid_provider(val: impl Into<String>) -> Self {
88 Self::CdnInvalidProvider(val.into())
89 }
90
91 pub fn cdn_feature_required(provider: &str, feature: &'static str) -> Self {
93 Self::CdnFeatureRequired(provider.to_string(), feature)
94 }
95}