//! Error type for Mawida.

use thiserror::Error;

/// The crate-wide error type.
#[derive(Error, Debug)]
pub enum MawidaError {
    #[error("io error: {0}")]
    Io(#[from] std::io::Error),

    #[error("image decode error: {0}")]
    Image(String),

    #[error("asset not found: {0}")]
    AssetNotFound(String),

    #[error("render backend error: {0}")]
    Backend(String),

    #[error("no compatible GPU adapter found")]
    NoAdapter,

    #[error("surface error: {0}")]
    Surface(String),

    #[error("script error: {0}")]
    Script(String),

    #[error("{0}")]
    Other(String),
}

/// Convenience alias used throughout the crate.
pub type Result<T> = std::result::Result<T, MawidaError>;

impl From<image::ImageError> for MawidaError {
    fn from(e: image::ImageError) -> Self {
        MawidaError::Image(e.to_string())
    }
}
