Skip to main content

lib_humus/language/
loader_error.rs

1// SPDX-FileCopyrightText: 2026 Slatian <baschdel@disroot.org>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5use fluent::FluentError;
6use fluent_syntax::parser::ParserError;
7use lib_humus_configuration::HumusConfigError;
8
9use std::fmt::Debug;
10use std::path::PathBuf;
11
12use crate::language::UnicodeLanguageIdentifier;
13
14/// Error that is returned when loading language information from the template directory fails.
15#[derive(Debug, thiserror::Error)]
16pub enum LanguageEngineLoaderError {
17	/// The languagge base directory doess not exist
18	//TODO: Split this error up
19	#[error("Language base directory {path:?} is not a directory or does not exist.")]
20	BaseDirectoryDoesNotExist {
21		/// The path where the directory is expected.
22		path: PathBuf,
23		/// Weather the path exists but is not a directory
24		is_other: bool,
25	},
26	/// There was an error reading the language manifest file
27	#[error("Problem reading languages manifest file: {0}")]
28	ErrorReadingManifest(#[source] HumusConfigError),
29	/// The language that is declared as the default language in the manifest doesn't have an entry in the `languages` map.
30	#[error(
31		"The default language {default_language} is not declared as a valid language in the manifest file. Please correct the `default_language` or add a `[language.{default_language}]` section."
32	)]
33	DefaultLanguageNotInManifest {
34		/// The `default_language` value that caused the problem.
35		default_language: UnicodeLanguageIdentifier,
36	},
37	/// The language defined as default language has the is_hidden flag set, ths is not allowed!
38	#[error(
39		"The default language {default_language} is declared in the manifest file with the is_hidden flag set, this is not allowed. Please correct the `default_language` or remove its is_hidden flag."
40	)]
41	DefaultLanguageMustNotBeHidden {
42		/// The `default_language` value that caused the problem.
43		default_language: UnicodeLanguageIdentifier,
44	},
45	/// There was a problem reading an ftl file for a specific language. This is a filesystem error.
46	#[error("Problem reading language file for {language} at {path:?}: {io_error}")]
47	ErrorReadingLanguageFile {
48		/// The language the file causing the error is for
49		language: UnicodeLanguageIdentifier,
50		/// The path of the trouble causing language file
51		path: PathBuf,
52		/// The actual I/O Error
53		#[source]
54		io_error: std::io::Error,
55	},
56	/// There was at least one problem parsing a ftl file.
57	#[error("Error parsing language file for language {language} at {path:?}: {errors:#?}")]
58	ErrorParsingLanguageFile {
59		/// The language the file causing the error is for
60		language: UnicodeLanguageIdentifier,
61		/// The path of the trouble causing language file
62		path: PathBuf,
63		/// The parsing error(s)
64		errors: Vec<ParserError>,
65	},
66	/// There were one or more errors while putting the parsed fluent resources into a budle.
67	#[error(
68		"Error adding language file to bundle for language {language} at {path:?}: {errors:#?}"
69	)]
70	ErrorAddingLanguageFile {
71		/// The language the file causing the error is for
72		language: UnicodeLanguageIdentifier,
73		/// The path of the trouble causing language file
74		path: PathBuf,
75		/// The error(s) that occurred
76		errors: Vec<FluentError>,
77	},
78}