use beet_core::prelude::*;
use std::path::Path;
use std::path::PathBuf;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Failed to parse templates:\nPath: {path}\nDetails:\n{err}")]
FileToTemplates { path: PathBuf, err: String },
#[error("Failed to collect templates:\nSpan: {span}\nDetails:\n{err}")]
CollectLangTemplates { span: FileSpan, err: String },
#[error("Failed to serialize:\nPath: {path}\nDetails:\n{err}")]
SerializeRon {
path: PathBuf,
err: ron::error::Error,
},
#[error("{0}")]
File(FsError),
#[error("Failed to parse css: {err}\nSpan: {span:?}")]
LightningCss { span: Option<FileSpan>, err: String },
}
impl Error {
pub fn serialize_ron(
path: impl AsRef<Path>,
err: ron::error::Error,
) -> Self {
Self::SerializeRon {
path: path.as_ref().to_path_buf(),
err,
}
}
pub fn file_to_templates(
path: impl AsRef<Path>,
err: impl ToString,
) -> Self {
Self::FileToTemplates {
path: path.as_ref().to_path_buf(),
err: err.to_string(),
}
}
pub fn collect_lang_templates(span: &FileSpan, err: impl ToString) -> Self {
Self::CollectLangTemplates {
span: span.clone(),
err: err.to_string(),
}
}
}