1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/// Error return codes for API functions.
///
/// Note that there is an [`ErrorCode::Success`],
/// so the presence of [`ErrorCode`] does NOT signify an error.
///
/// 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
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[non_exhaustive]
#[must_use]
#[repr(u32)]
pub enum ErrorCode {
/// Success - there was no error and the operation completed successfully
Success = 0,
/// API not available.
///
/// Typically happens if a module calls an API it has not specified that it requires
ApiNotAvailable = 2,
/// Internal error - something went wrong on in the Ark host
InternalError = 4,
/// Invalid arguments - the inputs to the called API function were not valid
InvalidArguments = 5,
/// Resource not found - used by APIs to indicate a requested resource can't be found
NotFound = 6,
/// The API or resource is currently not available
Unavailable = 7,
}
/// A result from an FFI function.
///
/// Because FFI functions cannot return multiple values, the actual type
/// returned from an FFI function will be just the error code. The actual value
/// that would be returned if the function was successful will be pulled from an
/// output argument that was passed to the extern function
pub type FFIResult<T> = Result<T, ErrorCode>;