Skip to main content

sal_virt/rfs/
error.rs

1use std::error::Error;
2use std::fmt;
3
4/// Error types for RFS operations
5#[derive(Debug)]
6pub enum RfsError {
7    /// Command execution failed
8    CommandFailed(String),
9    /// Invalid argument provided
10    InvalidArgument(String),
11    /// Mount operation failed
12    MountFailed(String),
13    /// Unmount operation failed
14    UnmountFailed(String),
15    /// List operation failed
16    ListFailed(String),
17    /// Pack operation failed
18    PackFailed(String),
19    /// Other error
20    Other(String),
21}
22
23impl fmt::Display for RfsError {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        match self {
26            RfsError::CommandFailed(msg) => write!(f, "RFS command failed: {}", msg),
27            RfsError::InvalidArgument(msg) => write!(f, "Invalid argument: {}", msg),
28            RfsError::MountFailed(msg) => write!(f, "Mount failed: {}", msg),
29            RfsError::UnmountFailed(msg) => write!(f, "Unmount failed: {}", msg),
30            RfsError::ListFailed(msg) => write!(f, "List failed: {}", msg),
31            RfsError::PackFailed(msg) => write!(f, "Pack failed: {}", msg),
32            RfsError::Other(msg) => write!(f, "Other error: {}", msg),
33        }
34    }
35}
36
37impl Error for RfsError {}
38
39impl From<std::io::Error> for RfsError {
40    fn from(error: std::io::Error) -> Self {
41        RfsError::Other(format!("IO error: {}", error))
42    }
43}