use freedesktop_entry_parser::ParseError as PE;
use std::{io, num::ParseIntError, path::PathBuf, str::Utf8Error};
use thiserror::Error;
#[cfg(feature = "expand-paths")]
use shellexpand::LookupError;
#[cfg(feature = "expand-paths")]
use std::env::VarError;
pub type Result<T> = std::result::Result<T, LiniconError>;
#[derive(Debug, Error)]
pub enum LiniconError {
#[error("Theme `{0}` not found")]
ThemeNotFound(String),
#[error("Index file not found for `{0}`")]
IndexFileNotFound(String),
#[error("Error parsing index file `{path}`")]
ParseIndex {
path: PathBuf,
#[source]
source: ParseError,
},
#[error("Error opening index file `{path}`")]
OpenIndex {
path: PathBuf,
#[source]
source: io::Error,
},
#[cfg(feature = "expand-paths")]
#[error("Error expanding path")]
ExapandPath(#[from] LookupError<VarError>)
}
#[derive(Debug, Error)]
pub enum ParseError {
#[error(transparent)]
ParseError(#[from] PE),
#[error("Index file conatins invalid UTF-8")]
UTT8Error(#[from] Utf8Error),
#[error("Field in the index file contains an invalid numeric value")]
ParseIntError(#[from] ParseIntError),
#[error("Index file is missing it's header")]
MissingHeader,
#[error(
"Icon {0} in the index file is missing the size field, which is required"
)]
MissingSize(String),
#[error("Icon {0} in the index file has an invalid type")]
InvalidType(String),
#[error("Index file doesn't contain any sections")]
EmptyIndexFile,
#[error("The first section of the index file is not titled `Icon Theme`")]
NoIconTheme,
}