soroban_sdk/
error.rs

1use core::convert::Infallible;
2
3use crate::xdr;
4
5/// InvokeError captures errors returned from the invocation of another
6/// contract.
7#[derive(Debug, Copy, Clone, Eq, PartialEq)]
8pub enum InvokeError {
9    /// Abort occurs if the invoke contract panicks with a [`panic!`], or a host
10    /// function of the environment has a failure, or a runtime error occurs.
11    Abort,
12    /// Contract error occurs if the invoked contract function exited returning
13    /// an error or called [`panic_with_error!`][crate::panic_with_error!] with
14    /// a [`contracterror`][crate::contracterror].
15    ///
16    /// If the contract defines a [`contracterror`][crate::contracterror] type
17    /// as part of its interface, this variant of the error will be convertible
18    /// to that type, but if that conversion failed then this variant of the
19    /// error would be used to represent the error.
20    Contract(u32),
21}
22
23impl From<crate::Error> for InvokeError {
24    fn from(e: crate::Error) -> Self {
25        if e.is_type(xdr::ScErrorType::Contract) {
26            InvokeError::Contract(e.get_code())
27        } else {
28            InvokeError::Abort
29        }
30    }
31}
32
33impl From<Infallible> for InvokeError {
34    fn from(_: Infallible) -> Self {
35        unreachable!()
36    }
37}