use super::ModelType;
#[derive(Debug, thiserror::Error)]
pub enum Omf1Error {
#[error("this is not an OMF1 file")]
NotOmf1,
#[error("version '{version}' is not supported")]
UnsupportedVersion { version: String },
#[error("wrong value type, found {found} when expecting {}", join(expected))]
WrongType {
found: ModelType,
expected: &'static [ModelType],
},
#[error("item '{key}' is missing from the file")]
MissingItem { key: String },
#[error("an integer array was expected, but floating-point was found")]
NonIntegerArray,
#[error("index {index} is outside the range 0 to 4294967295, or -1 for null categories")]
IndexOutOfRange { index: i64 },
#[error("JSON deserialization error: {0}")]
DeserializationFailed(#[from] serde_json::Error),
}
fn join(types: &[ModelType]) -> String {
match types {
[] => "none".to_owned(),
[t] => t.to_string(),
[t, s] => format!("{t} or {s}"),
[s @ .., t] => format!(
"{}, or {t}",
s.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(", ")
),
}
}