use std::io;
use std::path::PathBuf;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("{path}: {source}")]
Io {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("{path}: {message}")]
Config {
path: PathBuf,
message: String,
},
#[error("{path}:{line}:{column}: {message}")]
Json {
path: PathBuf,
line: u32,
column: u32,
message: String,
},
#[error("locale {locale:?}: {source}")]
Locale {
locale: String,
#[source]
source: mf2_locale_data::Error,
},
#[error("catalog for {locale}: {source}")]
Write {
locale: String,
#[source]
source: mf2_catalog::WriteError,
},
#[error(transparent)]
LocaleData(#[from] mf2_locale_data::Error),
#[error(transparent)]
Manifest(#[from] mf2_catalog::ManifestError),
#[error(transparent)]
Catalog(#[from] mf2_catalog::WriteError),
#[error("catalog for {locale}: {format}: {source}")]
Compress {
locale: String,
format: &'static str,
#[source]
source: io::Error,
},
#[error("{0}")]
Layout(String),
#[error("{errors} error{} in {locales} locale{}", plural(*errors), plural(*locales))]
Corpus {
errors: usize,
locales: usize,
},
}
fn plural(n: usize) -> &'static str {
if n == 1 { "" } else { "s" }
}
impl Error {
#[doc(hidden)]
pub fn io(path: impl Into<PathBuf>, source: io::Error) -> Error {
Error::Io {
path: path.into(),
source,
}
}
}