use super::TableType;
use crate::core::ValType;
use core::{fmt, fmt::Display};
#[derive(Debug)]
#[non_exhaustive]
pub enum TableError {
GrowOutOfBounds {
maximum: u32,
current: u32,
delta: u32,
},
ElementTypeMismatch {
expected: ValType,
actual: ValType,
},
AccessOutOfBounds {
current: u32,
offset: u32,
},
CopyOutOfBounds,
InvalidSubtype {
ty: TableType,
other: TableType,
},
TooManyTables,
}
#[cfg(feature = "std")]
impl std::error::Error for TableError {}
impl Display for TableError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::GrowOutOfBounds {
maximum,
current,
delta,
} => {
write!(
f,
"tried to grow table with size of {current} and maximum of \
{maximum} by {delta} out of bounds",
)
}
Self::ElementTypeMismatch { expected, actual } => {
write!(f, "encountered mismatching table element type, expected {expected:?} but found {actual:?}")
}
Self::AccessOutOfBounds { current, offset } => {
write!(
f,
"out of bounds access of table element {offset} \
of table with size {current}",
)
}
Self::CopyOutOfBounds => {
write!(f, "out of bounds access of table elements while copying")
}
Self::InvalidSubtype { ty, other } => {
write!(f, "table type {ty:?} is not a subtype of {other:?}",)
}
Self::TooManyTables => {
write!(f, "too many tables")
}
}
}
}