Skip to main content

hostcraft_core/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum HostCraftError {
5    Io(std::io::Error),
6    PermissionDenied(String),
7    UnsupportedPlatform(String),
8    DuplicateEntry,
9    EntryNotFound,
10    NoChange,
11}
12
13impl fmt::Display for HostCraftError {
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        match self {
16            HostCraftError::Io(e) => write!(f, "IO error: {}", e),
17            HostCraftError::PermissionDenied(msg) => write!(f, "Permission denied: {}", msg),
18            HostCraftError::UnsupportedPlatform(os) => write!(f, "Unsupported platform: {}", os),
19            HostCraftError::DuplicateEntry => write!(f, "You have inserted a duplicate entry."),
20            HostCraftError::EntryNotFound => write!(f, "Please check the name and try again."),
21            HostCraftError::NoChange => {
22                write!(f, "Entry already exists. No changes made.")
23            }
24        }
25    }
26}
27
28impl std::error::Error for HostCraftError {}
29
30pub type Result<T> = std::result::Result<T, HostCraftError>;