blob: bdbb46d33181ee50a8bff0ce219dc1fe9471c948 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
use std::result::Result as StdResult;
use fluent::FluentResource;
pub type Result<T> = StdResult<T, Error>;
/// Simple wrapper around the errors that may occur during the program's execution.
#[derive(Debug)]
pub enum Error {
/// A generic error - you are not supposed to ever actually encounter this, but it beats
/// using a wild unwrap in a library.
GenericError(String),
/// Wraps a [`std::io::Errror`] that occurred while reading the files.
IoError(std::io::Error),
/// Wraps a [`unic_langid::LanguageIdentifierError`] that occurred while parsing a language
/// identifier.
LanguageIdentifierError(unic_langid::LanguageIdentifierError),
/// Wraps any number of [`fluent::FluentError`] that have occurred while parsing.
FluentError(Vec<fluent::FluentError>),
/// Happens when you try to get a message that does not actually exist.
MissingMessageError(String)
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Self::IoError(err)
}
}
impl From<(FluentResource, Vec<fluent_syntax::parser::ParserError>)> for Error {
fn from(err: (FluentResource, Vec<fluent_syntax::parser::ParserError>)) -> Self {
let err = err.1.iter().map(|e| fluent::FluentError::ParserError(e.clone())).collect();
Self::FluentError(err)
}
}
impl From<Vec<fluent::FluentError>> for Error {
fn from(err: Vec<fluent::FluentError>) -> Self {
Self::FluentError(err)
}
}
impl From<unic_langid::LanguageIdentifierError> for Error {
fn from(err: unic_langid::LanguageIdentifierError) -> Self {
Self::LanguageIdentifierError(err)
}
}
|