1use super::ModelType;
2
3#[derive(Debug, thiserror::Error)]
8pub enum Omf1Error {
9 #[error("this is not an OMF1 file")]
11 NotOmf1,
12 #[error("version '{version}' is not supported")]
14 UnsupportedVersion { version: String },
15 #[error("wrong value type, found {found} when expecting {}", join(expected))]
17 WrongType {
18 found: ModelType,
19 expected: &'static [ModelType],
20 },
21 #[error("item '{key}' is missing from the file")]
23 MissingItem { key: String },
24 #[error("an integer array was expected, but floating-point was found")]
26 NonIntegerArray,
27 #[error("index {index} is outside the range 0 to 4294967295, or -1 for null categories")]
29 IndexOutOfRange { index: i64 },
30 #[error("JSON deserialization error: {0}")]
32 DeserializationFailed(#[from] serde_json::Error),
33}
34
35fn join(types: &[ModelType]) -> String {
36 match types {
37 [] => "none".to_owned(),
38 [t] => t.to_string(),
39 [t, s] => format!("{t} or {s}"),
40 [s @ .., t] => format!(
41 "{}, or {t}",
42 s.iter()
43 .map(ToString::to_string)
44 .collect::<Vec<_>>()
45 .join(", ")
46 ),
47 }
48}