fluent_templates/
error.rs1use std::fmt;
2
3use unic_langid::LanguageIdentifier;
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}
30
31#[derive(Debug)]
33pub struct FluentError(Vec<fluent_syntax::parser::ParserError>);
34
35impl From<Vec<fluent_syntax::parser::ParserError>> for FluentError {
36 fn from(errors: Vec<fluent_syntax::parser::ParserError>) -> Self {
37 Self(errors)
38 }
39}
40
41impl From<FluentError> for Vec<fluent_syntax::parser::ParserError> {
42 fn from(error: FluentError) -> Self {
43 error.0
44 }
45}
46
47impl fmt::Display for FluentError {
48 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49 for error in &self.0 {
50 write!(f, "{:?}", error)?;
51 }
52
53 Ok(())
54 }
55}
56
57impl std::error::Error for FluentError {}
58
59#[derive(Debug, thiserror::Error)]
61pub enum LookupError {
62 #[error("Couldn't retrieve message with ID `{0}`")]
63 MessageRetrieval(String),
64 #[error("Couldn't find attribute `{attribute}` for message-id `{message_id}`")]
65 AttributeNotFound {
66 message_id: String,
67 attribute: String,
68 },
69 #[error("Language ID `{0}` has not been loaded")]
70 LangNotLoaded(LanguageIdentifier),
71 #[error("Fluent errors: {0:?}")]
72 FluentError(Vec<fluent_bundle::FluentError>),
73}