//! Meka errors

/// Error type for meka
#[derive(Default, Debug)]
pub struct MekaError {
    /// Error message
    message: String,
}
impl MekaError {
    /// Create a new MekaError with the given message
    pub fn new<S: AsRef<str>>(msg: S) -> Self {
        let msg = msg.as_ref();
        MekaError {
            message: msg.to_string(),
        }
    }
}

impl From<nix::errno::Errno> for MekaError {
    fn from(err: nix::errno::Errno) -> Self {
        MekaError::new(err.desc())
    }
}

impl std::fmt::Display for MekaError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.message)
    }
}
