fluent_templates/
error.rs1use std::fmt;
2
3use unic_langid::{LanguageIdentifier, LanguageIdentifierError};
4
5#[derive(Debug, thiserror::Error)]
7pub enum LoaderError {
8 #[error("Error with {}\n: {}", path.display(), source)]
10 Fs {
11 path: std::path::PathBuf,
13 source: std::io::Error,
15 },
16 #[error("Error parsing Fluent\n: {}", source)]
18 Fluent {
19 #[from]
21 source: FluentError,
22 },
23 #[error("Failed to add FTL resources to the bundle")]
25 FluentBundle {
26 errors: Vec<fluent_bundle::FluentError>,
28 },
29 #[error("Error parsing LanguageIdentifier\n: {}", source)]
31 InvalidLanguageId {
32 #[from]
34 source: LanguageIdentifierError,
35 },
36}
37
38#[derive(Debug)]
40pub struct FluentError(Vec<fluent_syntax::parser::ParserError>);
41
42impl From<Vec<fluent_syntax::parser::ParserError>> for FluentError {
43 fn from(errors: Vec<fluent_syntax::parser::ParserError>) -> Self {
44 Self(errors)
45 }
46}
47
48impl From<FluentError> for Vec<fluent_syntax::parser::ParserError> {
49 fn from(error: FluentError) -> Self {
50 error.0
51 }
52}
53
54impl fmt::Display for FluentError {
55 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
56 for error in &self.0 {
57 write!(f, "{:?}", error)?;
58 }
59
60 Ok(())
61 }
62}
63
64impl std::error::Error for FluentError {}
65
66#[derive(Debug, thiserror::Error)]
68pub enum LookupError {
69 #[error("Couldn't retrieve message with ID `{0}`")]
70 MessageRetrieval(String),
71 #[error("Couldn't find attribute `{attribute}` for message-id `{message_id}`")]
72 AttributeNotFound {
73 message_id: String,
74 attribute: String,
75 },
76 #[error("Language ID `{0}` has not been loaded")]
77 LangNotLoaded(LanguageIdentifier),
78 #[error("Fluent errors: {0:?}")]
79 FluentError(Vec<fluent_bundle::FluentError>),
80}