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(
"locales {first:?} and {second:?} both give the generated `Locale::{variant}`: rename one"
)]
LocaleVariant {
first: String,
second: String,
variant: String,
},
#[error("markup names {first:?} and {second:?} have one hash: rename one")]
MarkupHash {
first: String,
second: String,
},
#[error("{errors} error{} in {locales} locale{}", plural(*errors), plural(*locales))]
Corpus {
errors: usize,
locales: usize,
},
#[error(
"mf2-build: this crate does not name `mf2` in its [dependencies], so its \
build script cannot see mf2's features (DEP_MF2_V2_FEATURES): add it \
there, as the crate that includes the generated module needs it anyway"
)]
NoMf2,
#[error(
"mf2-build {build} builds for mf2 {build}, but this crate's mf2 is {mf2}: \
name the same version of both"
)]
Mf2Version {
mf2: String,
build: String,
},
#[error(
"mf2-build: `mf2` has `datetime-icu`, whose catalogs carry ICU4X's date \
data: add `features = [\"icu-blob\"]` to this crate's `mf2-build` \
build-dependency"
)]
IcuBlob,
}
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,
}
}
}