mirror of
https://git.mentality.rip/numas13/xash3d-master.git
synced 2025-01-22 04:44:31 +00:00
protocol: remove thiserror
This commit is contained in:
parent
7c53bc40e3
commit
da06045f18
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -719,7 +719,6 @@ version = "0.2.0"
|
||||
dependencies = [
|
||||
"bitflags 2.5.0",
|
||||
"log",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -12,6 +12,5 @@ homepage = "https://xash.su"
|
||||
repository = "https://git.mentality.rip/numas13/xash3d-master"
|
||||
|
||||
[dependencies]
|
||||
thiserror = "1.0.49"
|
||||
log = "0.4.18"
|
||||
bitflags = "2.4"
|
||||
|
@ -6,43 +6,51 @@ use std::{
|
||||
mem, str,
|
||||
};
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use super::color;
|
||||
use super::wrappers::Str;
|
||||
|
||||
/// The error type for `Cursor` and `CursorMut`.
|
||||
#[derive(Error, Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum CursorError {
|
||||
/// Invalid number.
|
||||
#[error("Invalid number")]
|
||||
InvalidNumber,
|
||||
/// Invalid string.
|
||||
#[error("Invalid string")]
|
||||
InvalidString,
|
||||
/// Invalid boolean.
|
||||
#[error("Invalid boolean")]
|
||||
InvalidBool,
|
||||
/// Invalid table entry.
|
||||
#[error("Invalid table key")]
|
||||
InvalidTableKey,
|
||||
/// Invalid table entry.
|
||||
#[error("Invalid table entry")]
|
||||
InvalidTableValue,
|
||||
/// Table end found.
|
||||
#[error("Table end")]
|
||||
TableEnd,
|
||||
/// Expected data not found.
|
||||
#[error("Expected data not found")]
|
||||
Expect,
|
||||
/// An unexpected data found.
|
||||
#[error("Unexpected data")]
|
||||
ExpectEmpty,
|
||||
/// Buffer size is no enougth to decode or encode a packet.
|
||||
#[error("Unexpected end of buffer")]
|
||||
UnexpectedEnd,
|
||||
}
|
||||
|
||||
impl fmt::Display for CursorError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
let s = match self {
|
||||
Self::InvalidNumber => "Invalid number",
|
||||
Self::InvalidString => "Invalid string",
|
||||
Self::InvalidBool => "Invalid boolean",
|
||||
Self::InvalidTableKey => "Invalid table key",
|
||||
Self::InvalidTableValue => "Invalid table entry",
|
||||
Self::TableEnd => "Table end",
|
||||
Self::Expect => "Expected data not found",
|
||||
Self::ExpectEmpty => "Unexpected data",
|
||||
Self::UnexpectedEnd => "Unexpected end of buffer",
|
||||
};
|
||||
s.fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for CursorError {}
|
||||
|
||||
pub type Result<T, E = CursorError> = std::result::Result<T, E>;
|
||||
|
||||
pub trait GetKeyValue<'a>: Sized {
|
||||
|
@ -20,11 +20,11 @@ pub mod master;
|
||||
pub mod server;
|
||||
pub mod wrappers;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
pub use cursor::CursorError;
|
||||
pub use server_info::ServerInfo;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::filter::Version;
|
||||
|
||||
/// Current protocol version.
|
||||
@ -33,30 +33,53 @@ pub const PROTOCOL_VERSION: u8 = 49;
|
||||
pub const CLIENT_VERSION: Version = Version::new(0, 20);
|
||||
|
||||
/// The error type for decoding and encoding packets.
|
||||
#[derive(Error, Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum Error {
|
||||
/// Failed to decode a packet.
|
||||
#[error("Invalid packet")]
|
||||
InvalidPacket,
|
||||
/// Invalid region.
|
||||
#[error("Invalid region")]
|
||||
InvalidRegion,
|
||||
/// Invalid client announce IP.
|
||||
#[error("Invalid client announce IP")]
|
||||
InvalidClientAnnounceIp,
|
||||
/// Invalid last IP.
|
||||
#[error("Invalid last server IP")]
|
||||
InvalidQueryServersLast,
|
||||
/// Server protocol version is not supported.
|
||||
#[error("Invalid protocol version")]
|
||||
InvalidProtocolVersion,
|
||||
/// Cursor error.
|
||||
#[error("{0}")]
|
||||
CursorError(#[from] CursorError),
|
||||
CursorError(CursorError),
|
||||
/// Invalid value for server add packet.
|
||||
#[error("Invalid value for server add key `{0}`: {1}")]
|
||||
InvalidServerValue(&'static str, #[source] CursorError),
|
||||
InvalidServerValue(&'static str, CursorError),
|
||||
/// Invalid value for query servers packet.
|
||||
#[error("Invalid value for filter key `{0}`: {1}")]
|
||||
InvalidFilterValue(&'static str, #[source] CursorError),
|
||||
InvalidFilterValue(&'static str, CursorError),
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Self::InvalidPacket => "Invalid packet".fmt(fmt),
|
||||
Self::InvalidRegion => "Invalid region".fmt(fmt),
|
||||
Self::InvalidClientAnnounceIp => "Invalid client announce IP".fmt(fmt),
|
||||
Self::InvalidQueryServersLast => "Invalid last server IP".fmt(fmt),
|
||||
Self::InvalidProtocolVersion => "Invalid protocol version".fmt(fmt),
|
||||
Self::CursorError(source) => source.fmt(fmt),
|
||||
Self::InvalidServerValue(key, source) => {
|
||||
write!(
|
||||
fmt,
|
||||
"Invalid value for server add key `{}`: {}",
|
||||
key, source
|
||||
)
|
||||
}
|
||||
Self::InvalidFilterValue(key, source) => {
|
||||
write!(fmt, "Invalid value for filter key `{}`: {}", key, source)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
impl From<CursorError> for Error {
|
||||
fn from(source: CursorError) -> Self {
|
||||
Self::CursorError(source)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user