lib-humus 0.6.0

Helps creating configurable frontends for humans and computers using axum, Tera and toml.
Documentation
// SPDX-FileCopyrightText: 2026 Slatian <baschdel@disroot.org>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

use fluent::FluentError;
use fluent_syntax::parser::ParserError;
use lib_humus_configuration::HumusConfigError;

use std::fmt::Debug;
use std::path::PathBuf;

use crate::language::UnicodeLanguageIdentifier;

/// Error that is returned when loading language information from the template directory fails.
#[derive(Debug, thiserror::Error)]
pub enum LanguageEngineLoaderError {
	/// The languagge base directory doess not exist
	//TODO: Split this error up
	#[error("Language base directory {path:?} is not a directory or does not exist.")]
	BaseDirectoryDoesNotExist {
		/// The path where the directory is expected.
		path: PathBuf,
		/// Weather the path exists but is not a directory
		is_other: bool,
	},
	/// There was an error reading the language manifest file
	#[error("Problem reading languages manifest file: {0}")]
	ErrorReadingManifest(#[source] HumusConfigError),
	/// The language that is declared as the default language in the manifest doesn't have an entry in the `languages` map.
	#[error(
		"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."
	)]
	DefaultLanguageNotInManifest {
		/// The `default_language` value that caused the problem.
		default_language: UnicodeLanguageIdentifier,
	},
	/// The language defined as default language has the is_hidden flag set, ths is not allowed!
	#[error(
		"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."
	)]
	DefaultLanguageMustNotBeHidden {
		/// The `default_language` value that caused the problem.
		default_language: UnicodeLanguageIdentifier,
	},
	/// There was a problem reading an ftl file for a specific language. This is a filesystem error.
	#[error("Problem reading language file for {language} at {path:?}: {io_error}")]
	ErrorReadingLanguageFile {
		/// The language the file causing the error is for
		language: UnicodeLanguageIdentifier,
		/// The path of the trouble causing language file
		path: PathBuf,
		/// The actual I/O Error
		#[source]
		io_error: std::io::Error,
	},
	/// There was at least one problem parsing a ftl file.
	#[error("Error parsing language file for language {language} at {path:?}: {errors:#?}")]
	ErrorParsingLanguageFile {
		/// The language the file causing the error is for
		language: UnicodeLanguageIdentifier,
		/// The path of the trouble causing language file
		path: PathBuf,
		/// The parsing error(s)
		errors: Vec<ParserError>,
	},
	/// There were one or more errors while putting the parsed fluent resources into a budle.
	#[error(
		"Error adding language file to bundle for language {language} at {path:?}: {errors:#?}"
	)]
	ErrorAddingLanguageFile {
		/// The language the file causing the error is for
		language: UnicodeLanguageIdentifier,
		/// The path of the trouble causing language file
		path: PathBuf,
		/// The error(s) that occurred
		errors: Vec<FluentError>,
	},
}