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,
InvalidIdentifier,
InvalidEscapeCharacter,
InvalidFloatNumber,
MissingExponent,
InvalidMapKeyType,
MapMissingValue,
UnclosedMap,
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::InvalidIdentifier => write!(f, "Invalid identifier"),
Self::InvalidEscapeCharacter => write!(f, "Invalid escape character"),
Self::InvalidFloatNumber => write!(f, "Failed to parse a floating-point number"),
Self::MissingExponent => write!(f, "A floating-point number is missing an exponent"),
Self::InvalidMapKeyType => write!(f, "Invalid map key type"),
Self::MapMissingValue => write!(f, "Map has a key without a corresponding value"),
Self::UnclosedMap => write!(
f,
"Input ended before an identifier marking the end of a map"
),
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 {
NanEncountered,
RecursionLimitExceeded,
}
impl fmt::Display for SerializationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::NanEncountered => write!(f, "Encountered a NaN"),
Self::RecursionLimitExceeded => write!(f, "Recursion limit exceeded"),
}
}
}
impl error::Error for SerializationError {}