use core::fmt;
use std::error;
use core::num::ParseFloatError;
use weakauras_codec_lua_value::error::TryFromLuaValueError;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeserializationError {
InvalidPrefix,
InvalidTag,
InvalidEmbeddedTag,
InvalidStringReference,
InvalidMapReference,
InvalidFloatNumber,
InvalidMapKeyType,
UnexpectedEof,
RecursionLimitExceeded,
}
impl From<ParseFloatError> for DeserializationError {
fn from(_value: ParseFloatError) -> Self {
Self::InvalidFloatNumber
}
}
impl From<TryFromLuaValueError> for DeserializationError {
fn from(_value: TryFromLuaValueError) -> Self {
Self::InvalidMapKeyType
}
}
impl fmt::Display for DeserializationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::InvalidPrefix => write!(f, "Invalid prefix"),
Self::InvalidTag => write!(f, "Invalid tag"),
Self::InvalidEmbeddedTag => write!(f, "Invalid embedded tag"),
Self::InvalidStringReference => write!(f, "Invalid string reference"),
Self::InvalidMapReference => write!(f, "Invalid map reference"),
Self::InvalidFloatNumber => write!(f, "Failed to parse a floating-point number"),
Self::InvalidMapKeyType => write!(f, "Invalid map key type"),
Self::UnexpectedEof => write!(f, "Unexpected EOF"),
Self::RecursionLimitExceeded => write!(f, "Recursion limit exceeded"),
}
}
}
impl error::Error for DeserializationError {}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SerializationError {
TooManyUniqueStrings,
StringIsTooLarge,
MapIsTooLarge,
ArrayIsTooLarge,
RecursionLimitExceeded,
}
impl fmt::Display for SerializationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::TooManyUniqueStrings => write!(f, "Too many unique strings"),
Self::StringIsTooLarge => write!(f, "String is too large"),
Self::MapIsTooLarge => write!(f, "Map is too large"),
Self::ArrayIsTooLarge => write!(f, "Array is too large"),
Self::RecursionLimitExceeded => write!(f, "Recursion limit exceeded"),
}
}
}
impl error::Error for SerializationError {}