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