1use std::fmt;
2
3#[derive(Debug, Clone)]
5pub enum ConversionError {
6 InvalidId(String),
8 UnknownVariant {
10 type_name: &'static str,
11 value: String,
12 },
13 Json(String),
15 Base64(String),
17 Gzip(String),
19 UnsupportedVersion(u32),
21 IdIndexMismatch { expected: u64, actual: u64 },
23}
24
25impl fmt::Display for ConversionError {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 Self::InvalidId(s) => write!(f, "invalid ID string: {s:?}"),
29 Self::UnknownVariant { type_name, value } => {
30 write!(f, "unknown {type_name} variant: {value:?}")
31 }
32 Self::Json(msg) => write!(f, "JSON error: {msg}"),
33 Self::Base64(msg) => write!(f, "base64 decode error: {msg}"),
34 Self::Gzip(msg) => write!(f, "gzip decode error: {msg}"),
35 Self::UnsupportedVersion(v) => write!(f, "unsupported schema version: {v}"),
36 Self::IdIndexMismatch { expected, actual } => {
37 write!(
38 f,
39 "arena slot ID mismatch: expected {expected}, got {actual}"
40 )
41 }
42 }
43 }
44}
45
46impl std::error::Error for ConversionError {}
47
48impl From<serde_json::Error> for ConversionError {
49 fn from(err: serde_json::Error) -> Self {
50 Self::Json(err.to_string())
51 }
52}