cross_path/
error.rs

1use std::fmt;
2
3/// Path error type
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum PathError {
6    /// Invalid path
7    InvalidPath(String),
8
9    /// Encoding error
10    EncodingError(String),
11
12    /// Security error
13    SecurityError(String),
14
15    /// Platform-specific error
16    PlatformError(String),
17
18    /// Path normalization error
19    NormalizationError(String),
20
21    /// Path parsing error
22    ParseError(String),
23
24    /// IO error
25    IoError(String),
26
27    /// Unsupported path format
28    UnsupportedFormat(String),
29
30    /// Drive mapping error
31    DriveMappingError(String),
32}
33
34impl PathError {
35    /// Create new `InvalidPath` error
36    pub fn invalid_path(msg: impl Into<String>) -> Self {
37        Self::InvalidPath(msg.into())
38    }
39
40    /// Create new `EncodingError`
41    pub fn encoding_error(msg: impl Into<String>) -> Self {
42        Self::EncodingError(msg.into())
43    }
44
45    /// Create new `SecurityError`
46    pub fn security_error(msg: impl Into<String>) -> Self {
47        Self::SecurityError(msg.into())
48    }
49
50    /// Create new `PlatformError`
51    pub fn platform_error(msg: impl Into<String>) -> Self {
52        Self::PlatformError(msg.into())
53    }
54}
55
56impl fmt::Display for PathError {
57    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58        match self {
59            Self::InvalidPath(msg) => write!(f, "Invalid path: {msg}"),
60            Self::EncodingError(msg) => write!(f, "Encoding error: {msg}"),
61            Self::SecurityError(msg) => write!(f, "Security error: {msg}"),
62            Self::PlatformError(msg) => write!(f, "Platform error: {msg}"),
63            Self::NormalizationError(msg) => write!(f, "Normalization error: {msg}"),
64            Self::ParseError(msg) => write!(f, "Parse error: {msg}"),
65            Self::IoError(msg) => write!(f, "IO error: {msg}"),
66            Self::UnsupportedFormat(msg) => write!(f, "Unsupported format: {msg}"),
67            Self::DriveMappingError(msg) => write!(f, "Drive mapping error: {msg}"),
68        }
69    }
70}
71
72impl std::error::Error for PathError {}
73
74impl From<std::io::Error> for PathError {
75    fn from(err: std::io::Error) -> Self {
76        Self::IoError(err.to_string())
77    }
78}