Skip to main content

lingora_core/
error.rs

1use thiserror::*;
2
3/// Error type for the `lingora-core` crate.
4#[derive(Debug, Error)]
5pub enum LingoraError {
6    /// An I/O error occurred while reading/writing files (Fluent files, config, Rust sources, etc)
7    #[error(transparent)]
8    Io(#[from] std::io::Error),
9
10    /// Failed to deserialize `Lingora.toml` configuration file.
11    #[error(transparent)]
12    TomlParse(#[from] toml::de::Error),
13
14    /// Clap failed to parse command-line arguments.
15    #[error(transparent)]
16    Args(#[from] clap::Error),
17
18    /// Error originating from the `fluent4rs` parser while parsing `.ftl` files.
19    #[error(transparent)]
20    Fluent(#[from] fluent4rs::prelude::Fluent4rsError),
21
22    /// `syn` failed to parse Rust source code (used when scanning for `t!`, `te!`, `tid!` macros).
23    #[error(transparent)]
24    Syn(#[from] syn::Error),
25
26    /// The provided locale string is not a valid BCP 47 language tag.
27    /// Example: `"french"` instead of `"fr"`, or `"en_US"` (underscore instead of hyphen).
28    #[error("invalid locale: {0}")]
29    InvalidLocale(String),
30
31    /// A file path was given as a Fluent translation file, but it doesn't match expected
32    /// naming conventions or location rules (e.g. wrong extension, not under a locale dir).
33    #[error("invalid fluent file path: {0}")]
34    InvalidFluentPath(std::path::PathBuf),
35
36    /// A path was provided as a Rust source file to scan, but it cannot be processed
37    /// (wrong extension, not readable, outside project root, etc)
38    #[error("invalid rust file path: {0}")]
39    InvalidRustPath(std::path::PathBuf),
40
41    /// Multiple locale files resolve to the same primary language root, making it
42    /// impossible to determine a clean fallback chain (e.g. two files both treated as "en").
43    /// This usually indicates misconfiguration in `Lingora.toml` or ambiguous file naming.
44    #[error(
45        "multiple locales resolve to the same language root(s) making graceful fallback impossible for {0}"
46    )]
47    AmbiguousLanguageRoots(String),
48
49    /// The configuration or CLI arguments require translation files for certain locales,
50    /// but none were found on disk.
51    #[error("no translation file(s) for required locales: {0}")]
52    MissingTranslationFiles(String),
53
54    /// The workspace or configuration specifies locales, but none of them qualify as
55    /// *primary* locales (i.e. no non-variant/base-language documents were located).
56    #[error("no primary locales found for provided locales: {0}")]
57    MissingPrimaryLocales(String),
58
59    /// A string literal found in Rust code (inside a `t!`, `te!` or `tid!` macro)
60    /// does not conform to the expected Fluent identifier syntax.
61    ///
62    /// Examples of malformed literals:
63    /// - contains invalid characters
64    /// - starts with a digit
65    /// - has invalid dot/hyphen placement
66    #[error("malformed identifier literal {0}")]
67    MalformedIdentifierLiteral(String),
68}