Skip to main content

oneio/
error.rs

1use thiserror::Error;
2
3/// Error type for OneIO operations.
4#[derive(Debug, Error)]
5#[non_exhaustive]
6pub enum OneIoError {
7    /// All IO-related errors (file system, EOF, etc.)
8    #[error("IO error: {0}")]
9    Io(#[from] std::io::Error),
10
11    /// All network/remote operation errors (HTTP, FTP, S3, JSON parsing)
12    #[error("{0}")]
13    Network(Box<dyn std::error::Error + Send + Sync>),
14
15    /// Network error with URL context for debugging
16    #[error("{url}: {source}")]
17    NetworkWithContext {
18        source: Box<dyn std::error::Error + Send + Sync>,
19        url: String,
20    },
21
22    /// Structured status errors from remote services
23    #[error("{service} status error: {code}")]
24    Status { service: &'static str, code: u16 },
25
26    /// Invalid header name or value
27    #[error("Invalid header: {0}")]
28    InvalidHeader(String),
29
30    /// Invalid certificate data
31    #[error("Invalid certificate: {0}")]
32    InvalidCertificate(String),
33
34    /// Feature not supported/compiled
35    #[error("Not supported: {0}")]
36    NotSupported(String),
37}
38
39// Convert various network-related errors to Network variant
40#[cfg(feature = "http")]
41impl From<reqwest::Error> for OneIoError {
42    fn from(err: reqwest::Error) -> Self {
43        OneIoError::Network(Box::new(err))
44    }
45}
46
47#[cfg(feature = "ftp")]
48impl From<suppaftp::FtpError> for OneIoError {
49    fn from(err: suppaftp::FtpError) -> Self {
50        OneIoError::Network(Box::new(err))
51    }
52}
53
54#[cfg(feature = "json")]
55impl From<serde_json::Error> for OneIoError {
56    fn from(err: serde_json::Error) -> Self {
57        OneIoError::Network(Box::new(err))
58    }
59}
60
61#[cfg(feature = "s3")]
62impl From<s3::error::S3Error> for OneIoError {
63    fn from(err: s3::error::S3Error) -> Self {
64        OneIoError::Network(Box::new(err))
65    }
66}
67
68#[cfg(feature = "s3")]
69impl From<s3::creds::error::CredentialsError> for OneIoError {
70    fn from(err: s3::creds::error::CredentialsError) -> Self {
71        OneIoError::Network(Box::new(err))
72    }
73}
74
75#[cfg(feature = "s3")]
76impl From<s3::region::error::RegionError> for OneIoError {
77    fn from(err: s3::region::error::RegionError) -> Self {
78        OneIoError::Network(Box::new(err))
79    }
80}