use std::fmt;
use serde::Serialize;
#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(tag = "kind")]
pub enum MigrateError {
InvalidVersion { version: String },
Unsupported { version: String },
FromFuture { version: String },
NotAnObject,
Malformed {
step: &'static str,
pointer: String,
expected: &'static str,
},
Conflict {
step: &'static str,
pointer: String,
keys: Vec<String>,
},
MissingTable { step: &'static str, panel: String },
}
impl fmt::Display for MigrateError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidVersion { version } => write!(f, "invalid version `{version}`"),
Self::Unsupported { version } => {
write!(
f,
"configs written before 2.0.0 are unsupported (`{version}`)"
)
},
Self::FromFuture { version } => {
write!(f, "`{version}` is newer than this migrator")
},
Self::NotAnObject => write!(f, "expected a JSON object"),
Self::Malformed {
step,
pointer,
expected,
} => write!(f, "{step}: expected {expected} at `{pointer}`"),
Self::Conflict {
step,
pointer,
keys,
} => write!(f, "{step}: conflicting keys {keys:?} at `{pointer}`"),
Self::MissingTable { step, panel } => {
write!(f, "{step}: panel `{panel}` has no `table`")
},
}
}
}
impl std::error::Error for MigrateError {}