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
//! All the errors defined by this crate.

use std::io::{self, ErrorKind};
use thiserror::Error;

/// An error from the Minecraft networking protocol.
#[derive(Error, Debug)]
pub enum MinecraftProtocolError {
    /// VarInt data was invalid according to the spec.
    #[error("invalid varint data")]
    InvalidVarInt,

    /// Recieved invalid state information from the server.
    #[error("invalid state")]
    InvalidState,

    /// Recieved incorrectly formatted status response from the server.
    #[error("invalid status response")]
    InvalidStatusResponse,
}

impl From<MinecraftProtocolError> for io::Error {
    fn from(err: MinecraftProtocolError) -> Self {
        io::Error::new(ErrorKind::InvalidData, err)
    }
}