use snafu::Snafu;
#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
pub enum Error {
#[snafu(display("Params is invalid: {message}"))]
Params { message: String },
#[snafu(display("Json is invalid: {source}"))]
Json { source: serde_json::Error },
#[snafu(display("Error font: {name} not found"))]
FontNotFound { name: String },
#[snafu(display("Error parse font: {message}"))]
ParseFont { message: String },
#[cfg(feature = "image-encoder")]
#[snafu(display("Io {file}: {source}"))]
Io {
file: String,
source: std::io::Error,
},
#[cfg(feature = "image-encoder")]
#[snafu(display("Image size is invalid, width: {width}, height: {height}"))]
Size { width: u32, height: u32 },
#[cfg(feature = "image-encoder")]
#[snafu(display("Image from raw is fail, size:{size}"))]
Raw { size: usize },
#[cfg(feature = "image-encoder")]
#[snafu(display("Error to parse: {source}"))]
Parse { source: resvg::usvg::Error },
#[cfg(feature = "image-encoder")]
#[snafu(display("Encode fail: {source}"))]
Image { source: image::ImageError },
}
impl From<serde_json::Error> for Error {
fn from(value: serde_json::Error) -> Self {
Error::Json { source: value }
}
}
impl From<&str> for Error {
fn from(value: &str) -> Self {
Error::ParseFont {
message: value.to_string(),
}
}
}
pub type Result<T, E = Error> = std::result::Result<T, E>;