1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use std::error::Error;
use std::fmt;
use std::fmt::Display;

use crate::Frame;

/// This enum contains all error messages this library can return. Most API functions will generally return a `Result<(),GGRSError>`.
#[derive(Debug, Clone, PartialEq, Hash)]
pub enum GGRSError {
    /// When the prediction threshold has been reached, we cannot accept more inputs from the local player.
    PredictionThreshold,
    /// You made an invalid request, usually by using wrong parameters for function calls.
    InvalidRequest {
        /// Further specifies why the request was invalid.
        info: String,
    },
    /// In a `SyncTestSession`, this error is returned if checksums of resimulated frames do not match up with the original checksum.
    MismatchedChecksum {
        /// The frame at which the mismatch occurred.
        frame: Frame,
    },
    /// The Session is not synchronized yet. Please start the session and wait a few ms to let the clients synchronize.
    NotSynchronized,
    /// The spectator got so far behind the host that catching up is impossible.
    SpectatorTooFarBehind,
    /// Deprecated, will be removed in next major release
    SocketCreationFailed,
    /// Deprecated, will be removed in next major release
    PlayerDisconnected,
    /// Deprecated, will be removed in next major release
    DecodingError,
}

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 { frame } => {
                write!(
                    f,
                    "Detected checksum mismatch during rollback on frame {}.",
                    frame
                )
            }
            GGRSError::SpectatorTooFarBehind => {
                write!(
                    f,
                    "The spectator got so far behind the host that catching up is impossible."
                )
            }
            GGRSError::SocketCreationFailed => {
                write!(
                    f,
                    "Deprecated, will be removed in next major release."
                )
            }
            GGRSError::PlayerDisconnected => {
                write!(
                    f,
                    "Deprecated, will be removed in next major release."
                )
            }
            GGRSError::DecodingError => {
                write!(
                    f,
                    "Deprecated, will be removed in next major release."
                )
            }
            
        }
    }
}

impl Error for GGRSError {}