soroban_wasmi/table/
error.rs1use super::TableType;
2use crate::core::ValType;
3use core::{fmt, fmt::Display};
4
5#[derive(Debug)]
7#[non_exhaustive]
8pub enum TableError {
9 GrowOutOfBounds {
11 maximum: u32,
13 current: u32,
15 delta: u32,
17 },
18 ElementTypeMismatch {
20 expected: ValType,
22 actual: ValType,
24 },
25 AccessOutOfBounds {
27 current: u32,
29 offset: u32,
31 },
32 CopyOutOfBounds,
34 InvalidSubtype {
36 ty: TableType,
38 other: TableType,
40 },
41 TooManyTables,
42}
43
44#[cfg(feature = "std")]
45impl std::error::Error for TableError {}
46
47impl Display for TableError {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 match self {
50 Self::GrowOutOfBounds {
51 maximum,
52 current,
53 delta,
54 } => {
55 write!(
56 f,
57 "tried to grow table with size of {current} and maximum of \
58 {maximum} by {delta} out of bounds",
59 )
60 }
61 Self::ElementTypeMismatch { expected, actual } => {
62 write!(f, "encountered mismatching table element type, expected {expected:?} but found {actual:?}")
63 }
64 Self::AccessOutOfBounds { current, offset } => {
65 write!(
66 f,
67 "out of bounds access of table element {offset} \
68 of table with size {current}",
69 )
70 }
71 Self::CopyOutOfBounds => {
72 write!(f, "out of bounds access of table elements while copying")
73 }
74 Self::InvalidSubtype { ty, other } => {
75 write!(f, "table type {ty:?} is not a subtype of {other:?}",)
76 }
77 Self::TooManyTables => {
78 write!(f, "too many tables")
79 }
80 }
81 }
82}