fluent_static_codegen/
error.rs1use std::{collections::BTreeSet, path::PathBuf};
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5 #[error(transparent)]
6 IoError(#[from] std::io::Error),
7
8 #[error("Error reading resource {path}")]
9 ResourceReadError {
10 path: PathBuf,
11 source: std::io::Error,
12 },
13
14 #[error("Error reading resource from '{0}' while no `base_dir` is configured")]
15 UnexpectedRelativePath(PathBuf),
16
17 #[error(transparent)]
18 PathPrefixError(#[from] std::path::StripPrefixError),
19
20 #[error("Path contans invalid symbols: {0}")]
21 InvalidPathSymbol(PathBuf),
22
23 #[error("Path doesn not match the expected format {0}")]
24 InvalidPathFormat(PathBuf),
25
26 #[error("Error parsing fluent resource")]
27 FluentParserError {
28 errors: Vec<fluent_syntax::parser::ParserError>,
29 },
30
31 #[error(transparent)]
32 InvalidLanguageId(#[from] unic_langid::LanguageIdentifierError),
33
34 #[error("Error parsing Fluent resource {path}")]
35 FluentResourceParseError {
36 path: PathBuf,
37 errors: Vec<fluent_syntax::parser::ParserError>,
38 },
39
40 #[error(transparent)]
41 SyntaxError(#[from] syn::Error),
42
43 #[error("Found unsupported feature {feature}: {id}")]
44 UnsupportedFeature { feature: String, id: String },
45
46 #[error("No l10n resources found for fallback language {0}")]
47 FallbackLanguageNotFound(String),
48
49 #[error("Message bundle {bundle} integrity validation failed")]
50 MessageBundleValidationError {
51 bundle: String,
52 path: Option<String>,
53 entries: Vec<MessageValidationErrorEntry>,
54 },
55
56 #[error("Message bundle builder context is in an invalid state")]
57 UnexpectedContextState,
58
59 #[error("Error parsing literal value {0}")]
60 InvalidLiteral(String),
61
62 #[error(transparent)]
63 LexErr(#[from] proc_macro2::LexError),
64
65 #[error("Found duplicated entry with ID '{0}'")]
66 DuplicateEntryId(String),
67
68 #[error("Message bundle default language '{lang}' has not corresponding fluent resources")]
69 UnsupportedDefaultLanguage { lang: String },
70
71 #[error("Message {message_id} selector must have exactly one default variant")]
72 InvalidSelectorDefaultVariant { message_id: String },
73
74 #[error("Term {term_id} reference contains undeclared argument '{arg_name}'")]
75 UndeclaredTermArgument { term_id: String, arg_name: String },
76
77 #[error("Entry {entry_id} references undeclared message '{reference_id}'. Declare message '{reference_id}' before use.")]
78 UndeclaredMessageReference {
79 entry_id: String,
80 reference_id: String,
81 },
82
83 #[error("Entry {entry_id} references undeclared term '{reference_id}'. Declare term '{reference_id}' before use.")]
84 UndeclaredTermReference {
85 entry_id: String,
86 reference_id: String,
87 },
88
89 #[error("Entry {entry_id} references unimplemented function '{function_id}'. Register function in function registry before use.")]
90 UnimplementedFunction {
91 entry_id: String,
92 function_id: String,
93 },
94}
95
96#[derive(Debug)]
97pub struct MessageValidationErrorEntry {
98 pub message_id: String,
99 pub defined_in_languages: BTreeSet<String>,
100 pub undefined_in_languages: BTreeSet<String>,
101}