ark_api_ffi/error_code.rs
1/// Error return codes for API functions.
2///
3/// Note that there is an [`ErrorCode::Success`],
4/// so the presence of [`ErrorCode`] does NOT signify an error.
5///
6/// Do NOT use this type in the public interface of `ark-api`. Use idiomatic Rust error enum or [`ark_api::Error`](https://ark.embark.dev/api/ark_api/enum.Error.html) instead
7#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
8#[non_exhaustive]
9#[must_use]
10#[repr(u32)]
11pub enum ErrorCode {
12 /// Success - there was no error and the operation completed successfully
13 Success = 0,
14
15 /// API not available.
16 ///
17 /// Typically happens if a module calls an API it has not specified that it requires
18 ApiNotAvailable = 2,
19
20 /// Internal error - something went wrong on in the Ark host
21 InternalError = 4,
22
23 /// Invalid arguments - the inputs to the called API function were not valid
24 InvalidArguments = 5,
25
26 /// Resource not found - used by APIs to indicate a requested resource can't be found
27 NotFound = 6,
28
29 /// The API or resource is currently not available
30 Unavailable = 7,
31
32 /// HTTP request failed due to external server error - something went wrong when communicating with the remote server
33 ///
34 /// This can happen when sending a HTTP request to a server that is unavailable, if DNS lookup fails, or other server related issues.
35 HttpRequestFailed = 8,
36}
37
38/// A result from an FFI function.
39///
40/// Because FFI functions cannot return multiple values, the actual type
41/// returned from an FFI function will be just the error code. The actual value
42/// that would be returned if the function was successful will be pulled from an
43/// output argument that was passed to the extern function
44pub type FFIResult<T> = Result<T, ErrorCode>;