soroban_wasmi/func/
error.rs

1use core::{fmt, fmt::Display};
2
3/// Errors that can occur upon type checking function signatures.
4#[derive(Debug)]
5pub enum FuncError {
6    /// The exported function could not be found.
7    ExportedFuncNotFound,
8    /// A function parameter did not match the required type.
9    MismatchingParameterType,
10    /// Specified an incorrect number of parameters.
11    MismatchingParameterLen,
12    /// A function result did not match the required type.
13    MismatchingResultType,
14    /// Specified an incorrect number of results.
15    MismatchingResultLen,
16}
17
18#[cfg(feature = "std")]
19impl std::error::Error for FuncError {}
20
21impl Display for FuncError {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        match self {
24            FuncError::ExportedFuncNotFound => {
25                write!(f, "could not find exported function")
26            }
27            FuncError::MismatchingParameterType => {
28                write!(f, "encountered incorrect function parameter type")
29            }
30            FuncError::MismatchingParameterLen => {
31                write!(f, "encountered an incorrect number of parameters")
32            }
33            FuncError::MismatchingResultType => {
34                write!(f, "encountered incorrect function result type")
35            }
36            FuncError::MismatchingResultLen => {
37                write!(f, "encountered an incorrect number of results")
38            }
39        }
40    }
41}