1 use crate::resolver::ResolverError;
2 use fluent_syntax::parser::ParserError;
5 #[derive(Debug, PartialEq, Clone)]
12 impl std::fmt::Display for EntryKind {
13 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15 Self::Message => f.write_str("message"),
16 Self::Term => f.write_str("term"),
17 Self::Function => f.write_str("function"),
22 /// Core error type for Fluent runtime system.
24 /// It contains three main types of errors that may come up
25 /// during runtime use of the fluent-bundle crate.
26 #[derive(Debug, PartialEq, Clone)]
27 pub enum FluentError {
28 /// An error which occurs when
29 /// [`FluentBundle::add_resource`](crate::bundle::FluentBundle::add_resource)
30 /// adds entries that are already registered in a given [`FluentBundle`](crate::FluentBundle).
35 /// use fluent_bundle::{FluentBundle, FluentResource};
36 /// use unic_langid::langid;
38 /// let ftl_string = String::from("intro = Welcome, { $name }.");
39 /// let res1 = FluentResource::try_new(ftl_string)
40 /// .expect("Could not parse an FTL string.");
42 /// let ftl_string = String::from("intro = Hi, { $name }.");
43 /// let res2 = FluentResource::try_new(ftl_string)
44 /// .expect("Could not parse an FTL string.");
46 /// let langid_en = langid!("en-US");
47 /// let mut bundle = FluentBundle::new(vec![langid_en]);
49 /// bundle.add_resource(&res1)
50 /// .expect("Failed to add FTL resources to the bundle.");
52 /// assert!(bundle.add_resource(&res2).is_err());
58 ParserError(ParserError),
59 ResolverError(ResolverError),
62 impl std::fmt::Display for FluentError {
63 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65 Self::Overriding { kind, id } => {
66 write!(f, "Attempt to override an existing {}: \"{}\".", kind, id)
68 Self::ParserError(err) => write!(f, "Parser error: {}", err),
69 Self::ResolverError(err) => write!(f, "Resolver error: {}", err),
74 impl Error for FluentError {}
76 impl From<ResolverError> for FluentError {
77 fn from(error: ResolverError) -> Self {
78 Self::ResolverError(error)
82 impl From<ParserError> for FluentError {
83 fn from(error: ParserError) -> Self {
84 Self::ParserError(error)