Skip to main content

ferro_storage/
error.rs

1//! Error types for storage operations.
2
3use std::io;
4use thiserror::Error;
5
6/// Storage error types.
7#[derive(Error, Debug)]
8pub enum Error {
9    /// File not found.
10    #[error("File not found: {0}")]
11    NotFound(String),
12
13    /// Permission denied.
14    #[error("Permission denied: {0}")]
15    PermissionDenied(String),
16
17    /// IO error.
18    #[error("IO error: {0}")]
19    Io(#[from] io::Error),
20
21    /// Invalid path.
22    #[error("Invalid path: {0}")]
23    InvalidPath(String),
24
25    /// Disk not configured.
26    #[error("Disk not configured: {0}")]
27    DiskNotConfigured(String),
28
29    /// S3 error.
30    #[cfg(feature = "s3")]
31    #[error("S3 error: {0}")]
32    S3(String),
33
34    /// Feature not yet implemented.
35    #[error("Not implemented: {0}")]
36    NotImplemented(String),
37
38    /// Serialization error.
39    #[error("Serialization error: {0}")]
40    Serialization(String),
41
42    /// CDN operation error.
43    #[error("CDN error: {0}")]
44    Cdn(String),
45}
46
47impl Error {
48    /// Create a not found error.
49    pub fn not_found(path: impl Into<String>) -> Self {
50        Self::NotFound(path.into())
51    }
52
53    /// Create a permission denied error.
54    pub fn permission_denied(msg: impl Into<String>) -> Self {
55        Self::PermissionDenied(msg.into())
56    }
57
58    /// Create an invalid path error.
59    pub fn invalid_path(path: impl Into<String>) -> Self {
60        Self::InvalidPath(path.into())
61    }
62
63    /// Create a disk not configured error.
64    pub fn disk_not_configured(disk: impl Into<String>) -> Self {
65        Self::DiskNotConfigured(disk.into())
66    }
67
68    /// Create a not implemented error.
69    pub fn not_implemented(feature: impl Into<String>) -> Self {
70        Self::NotImplemented(feature.into())
71    }
72
73    /// Create a CDN error.
74    pub fn cdn(msg: impl Into<String>) -> Self {
75        Self::Cdn(msg.into())
76    }
77}