use std::error::Error;
use std::fmt;
use std::fmt::Display;
use crate::Frame;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GgrsError {
PredictionThreshold,
InvalidRequest {
info: String,
},
MismatchedChecksum {
current_frame: Frame,
mismatched_frames: Vec<Frame>,
},
NotSynchronized,
SpectatorTooFarBehind,
NotEnoughData,
}
impl Display for GgrsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::PredictionThreshold => {
write!(
f,
"Prediction threshold is reached, cannot proceed without catching up."
)
}
Self::InvalidRequest { info } => {
write!(f, "Invalid Request: {info}")
}
Self::NotSynchronized => {
write!(
f,
"The session is not yet synchronized with all remote sessions."
)
}
Self::MismatchedChecksum {
current_frame,
mismatched_frames,
} => {
write!(
f,
"Detected checksum mismatch during rollback on frame {current_frame}, mismatched frames: {mismatched_frames:?}",
)
}
Self::SpectatorTooFarBehind => {
write!(
f,
"The spectator got so far behind the host that catching up is impossible."
)
}
Self::NotEnoughData => {
write!(
f,
"Not enough data has been collected yet. Retry after at least one second."
)
}
}
}
}
impl Error for GgrsError {}