Skip to main content

adguard_flm/io/
error.rs

1use std::io::ErrorKind;
2
3/// General I/O Errors enum
4#[derive(Debug, thiserror::Error, PartialEq)]
5#[non_exhaustive]
6pub enum IOError {
7    /// Resource not found
8    #[error("Path not found: {0}")]
9    NotFound(String),
10
11    /// Resource permission denied
12    #[error("Permission denied: {0}")]
13    PermissionDenied(String),
14
15    /// Resource already exist
16    #[error("Path already exists: {0}")]
17    AlreadyExists(String),
18
19    /// Timeout
20    #[error("Timeout: {0}")]
21    TimedOut(String),
22
23    #[error("{0}")]
24    /// Other errors
25    Other(String),
26}
27
28impl From<std::io::Error> for IOError {
29    fn from(value: std::io::Error) -> Self {
30        match value.kind() {
31            ErrorKind::NotFound => Self::NotFound(value.to_string()),
32            ErrorKind::PermissionDenied => Self::PermissionDenied(value.to_string()),
33            ErrorKind::AlreadyExists => Self::AlreadyExists(value.to_string()),
34            ErrorKind::TimedOut => Self::TimedOut(value.to_string()),
35            _ => Self::Other(value.to_string()),
36        }
37    }
38}