use thiserror::Error;
#[derive(Clone, Copy, PartialEq, Eq, Debug, Error)]
#[repr(u8)]
#[non_exhaustive]
pub enum CatalogError {
#[error("not an .mf2b catalog")]
Magic,
#[error("unsupported .mf2b format version")]
Version,
#[error("catalog was compiled against a different manifest")]
ManifestMismatch,
#[error("catalog is truncated")]
Truncated,
#[error("invalid catalog header")]
Header,
#[error("invalid section table")]
SectionTable,
#[error("a required section is missing")]
MissingSection,
#[error("invalid INDEX section")]
Index,
#[error("invalid LOCALE section")]
Locale,
#[error("invalid FUNCS section")]
Funcs,
#[error("invalid FALLBACK section")]
Fallback,
#[error("invalid NAMES section")]
Names,
#[error("invalid IDS section")]
Ids,
#[error("invalid STRINGS section")]
Strings,
}
#[cfg(feature = "writer")]
#[derive(Clone, PartialEq, Eq, Debug, Error)]
#[non_exhaustive]
pub enum WriteError {
#[error("string contains U+0000: {0:?}")]
Nul(alloc::string::String),
#[error("message {message}: variable ${name} is not in its slot list")]
UnknownVariable {
message: usize,
name: alloc::string::String,
},
#[error("message {message}: function :{name} is not in the manifest")]
UnknownFunction {
message: usize,
name: alloc::string::String,
},
#[error("message {message}: .input declares {name:?} for variable {variable:?}")]
InputName {
message: usize,
name: alloc::string::String,
variable: alloc::string::String,
},
#[error("message {message}: unsupported data-model node")]
Unsupported {
message: usize,
},
#[error("manifest: {0}")]
Manifest(&'static str),
#[error("catalog direction must be ltr or rtl")]
Dir,
#[error("LOCALE entry {0}: duplicate or malformed")]
LocaleEntry(u32),
#[error("fallback: {0}")]
Fallback(&'static str),
#[error("too large: {0}")]
TooLarge(&'static str),
#[error("internal writer error: {0}")]
Internal(&'static str),
}
#[cfg(feature = "decode")]
#[derive(Clone, PartialEq, Eq, Debug, Error)]
#[non_exhaustive]
pub enum DecodeError {
#[error("message is absent from the catalog")]
Absent,
#[error("malformed MESSAGES record")]
Malformed,
#[error("invalid string reference")]
String,
#[error("invalid NAMES entry")]
Names,
#[error("function index out of range")]
Function,
#[error("malformed COLD record")]
Cold,
}
#[cfg(feature = "manifest")]
#[derive(Clone, PartialEq, Eq, Debug, Error)]
#[non_exhaustive]
pub enum ManifestError {
#[error("not an .mf2m manifest")]
Magic,
#[error("unsupported manifest version")]
Version,
#[error("manifest is truncated or malformed")]
Truncated,
#[error("manifest string is not UTF-8")]
Utf8,
#[error("manifest hash does not match its content")]
Hash,
#[error("trailing bytes after the manifest")]
Trailing,
#[error("invalid manifest: {0}")]
Invalid(&'static str),
}