Skip to main content

thruput_sdk/exn/
wrapper.rs

1use crate::ContractTypeSpec;
2use crate::exn::fault::*;
3use crate::xdr::*;
4use core::fmt::Debug;
5#[cfg(not(target_arch = "riscv32"))]
6use thiserror::Error;
7
8// TODO: Maybe make the fault-strings into Error sources,
9// and figure out how to Display them at the right times.
10
11/// Plumbing errors resulting from making a contract call:
12#[derive(
13    Debug, PartialEq, ReadXDR, WriteXDR, ContractTypeSpec, ConstXDRSize,
14)]
15#[cfg_attr(not(target_arch = "riscv32"), derive(Error))]
16#[repr(i32)]
17pub enum CallingError {
18    #[cfg_attr(
19        not(target_arch = "riscv32"),
20        error("Invalid call: contract not found (or bad auth tokens)")
21    )]
22    Invalid = 0,
23
24    #[cfg_attr(
25        not(target_arch = "riscv32"),
26        error("Decoding a successful result: {0}")
27    )]
28    DecodingSuccess(FaultString) = 1,
29
30    #[cfg_attr(
31        not(target_arch = "riscv32"),
32        error("Decoding an exception result: {0}")
33    )]
34    DecodingException(FaultString) = 2,
35
36    #[cfg_attr(not(target_arch = "riscv32"), error("Encoding arguments: {0}"))]
37    EncodingArgs(FaultString) = 3,
38
39    /// The target address already had a frame open on the invocation stack,
40    /// so the runtime refused the call as reentrant. The callee never ran.
41    #[cfg_attr(
42        not(target_arch = "riscv32"),
43        error("Invalid call: target already has an open frame (reentrant)")
44    )]
45    Reentrance = 4,
46
47    /// Admitting the call would have exceeded the network's cross-invoke
48    /// depth bound. The callee never ran; the same call succeeds from a
49    /// shallower frame.
50    #[cfg_attr(
51        not(target_arch = "riscv32"),
52        error("Invalid call: cross-invoke depth bound reached")
53    )]
54    DepthExceeded = 5,
55}
56
57/// `Result<T, CallingError>::or_re_throw()` aborts with the typed
58/// `LibraryExn::Calling` exception (client-side interface path).
59impl crate::re_throw::ReThrow for CallingError {
60    #[cfg_attr(not(target_arch = "riscv32"), track_caller)]
61    fn re_throw(self) -> ! {
62        crate::exn::client_library_throw(self)
63    }
64}
65
66/// Plumbing errors resulting from handling a contract call:
67#[derive(
68    Debug, PartialEq, ReadXDR, WriteXDR, ContractTypeSpec, ConstXDRSize,
69)]
70#[cfg_attr(not(target_arch = "riscv32"), derive(Error))]
71#[repr(i32)]
72pub enum HandlingError {
73    #[cfg_attr(
74        not(target_arch = "riscv32"),
75        error("Decoding argument data: {0}")
76    )]
77    DecodingArgs(FaultString) = 0,
78
79    #[cfg_attr(
80        not(target_arch = "riscv32"),
81        error("Encoding successful result: {0}")
82    )]
83    EncodingSuccess(FaultString) = 1,
84
85    #[cfg_attr(
86        not(target_arch = "riscv32"),
87        error("Encoding exception result: {0}")
88    )]
89    EncodingException(FaultString) = 2,
90
91    #[cfg_attr(not(target_arch = "riscv32"), error("Encoding event: {0}"))]
92    EncodingEvent(FaultString) = 3,
93}
94
95/// Plumbing errors resulting from working with auth tokens:
96#[derive(
97    Debug, PartialEq, ReadXDR, WriteXDR, ContractTypeSpec, ConstXDRSize,
98)]
99#[cfg_attr(not(target_arch = "riscv32"), derive(Error))]
100#[repr(i32)]
101pub enum AuthTokenError {
102    #[cfg_attr(
103        not(target_arch = "riscv32"),
104        error("Encoding auth token: {0}")
105    )]
106    MintEncodeFailure(FaultString) = 0,
107    #[cfg_attr(
108        not(target_arch = "riscv32"),
109        error("Decoding auth token payload: {0}")
110    )]
111    ConsumeDecodeFailure(FaultString) = 1,
112
113    #[cfg_attr(
114        not(target_arch = "riscv32"),
115        error("Receiving auth token handles: {0}")
116    )]
117    ReceiveAuthHandlesFailure(FaultString) = 2,
118}
119
120impl crate::__contract_spec::ContractTypeName for CallingError {
121    const NAME: crate::__contract_spec::ContractSpecIdView<'static> =
122        crate::__contract_spec::ContractSpecIdView {
123            crate_name: ::core::env!("CARGO_PKG_NAME"),
124            major: crate::exn::EXN_ABI_MAJOR,
125            module_path: ::core::module_path!(),
126            declared: "CallingError",
127        };
128}
129
130impl crate::__contract_spec::ContractTypeName for HandlingError {
131    const NAME: crate::__contract_spec::ContractSpecIdView<'static> =
132        crate::__contract_spec::ContractSpecIdView {
133            crate_name: ::core::env!("CARGO_PKG_NAME"),
134            major: crate::exn::EXN_ABI_MAJOR,
135            module_path: ::core::module_path!(),
136            declared: "HandlingError",
137        };
138}
139
140impl crate::__contract_spec::ContractTypeName for AuthTokenError {
141    const NAME: crate::__contract_spec::ContractSpecIdView<'static> =
142        crate::__contract_spec::ContractSpecIdView {
143            crate_name: ::core::env!("CARGO_PKG_NAME"),
144            major: crate::exn::EXN_ABI_MAJOR,
145            module_path: ::core::module_path!(),
146            declared: "AuthTokenError",
147        };
148}