fluent_templates/
error.rsuse std::fmt;
use unic_langid::LanguageIdentifier;
#[derive(Debug, thiserror::Error)]
pub enum LoaderError {
#[error("Error with {}\n: {}", path.display(), source)]
Fs {
path: std::path::PathBuf,
source: std::io::Error,
},
#[error("Error parsing Fluent\n: {}", source)]
Fluent {
#[from]
source: FluentError,
},
#[error("Failed to add FTL resources to the bundle")]
FluentBundle {
errors: Vec<fluent_bundle::FluentError>,
},
}
#[derive(Debug)]
pub struct FluentError(Vec<fluent_syntax::parser::ParserError>);
impl From<Vec<fluent_syntax::parser::ParserError>> for FluentError {
fn from(errors: Vec<fluent_syntax::parser::ParserError>) -> Self {
Self(errors)
}
}
impl From<FluentError> for Vec<fluent_syntax::parser::ParserError> {
fn from(error: FluentError) -> Self {
error.0
}
}
impl fmt::Display for FluentError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for error in &self.0 {
write!(f, "{:?}", error)?;
}
Ok(())
}
}
impl std::error::Error for FluentError {}
#[derive(Debug, thiserror::Error)]
pub enum LookupError {
#[error("Couldn't retrieve message with ID `{0}`")]
MessageRetrieval(String),
#[error("Couldn't find attribute `{attribute}` for message-id `{message_id}`")]
AttributeNotFound {
message_id: String,
attribute: String,
},
#[error("Language ID `{0}` has not been loaded")]
LangNotLoaded(LanguageIdentifier),
#[error("Fluent errors: {0:?}")]
FluentError(Vec<fluent_bundle::FluentError>),
}