Skip to main content

Error

Trait Error 

Source
pub trait Error: Error {
    // Required methods
    fn module_name(&self) -> &str;
    fn code(&self) -> u32;

    // Provided methods
    fn into_call_result(self) -> CallResult
       where Self: Sized { ... }
    fn into_abort(self) -> Result<Error, Self>
       where Self: Sized { ... }
}
Expand description

A runtime error that gets propagated to the caller.

It extends std::error::Error with module name and error code so that errors can be easily serialized and transferred between different processes.

This trait can be derived:

const MODULE_NAME: &str = "my-module";
#[derive(Clone, Debug, Error, thiserror::Error)]
#[sdk_error(autonumber)] // `module_name` meta is required if `MODULE_NAME` isn't in scope
enum Error {
   #[error("invalid argument")]
   InvalidArgument,          // autonumbered to 0

   #[error("forbidden")]
   #[sdk_error(code = 401)]  // manually numbered to 403 (`code` or autonumbering is required)
   Forbidden,
}

Required Methods§

Source

fn module_name(&self) -> &str

Name of the module that emitted the error.

Source

fn code(&self) -> u32

Error code uniquely identifying the error.

Provided Methods§

Source

fn into_call_result(self) -> CallResult
where Self: Sized,

Converts the error into a call result.

Source

fn into_abort(self) -> Result<Error, Self>
where Self: Sized,

Consumes self and returns either Ok(err) (where err is a dispatcher error) when batch should abort or Err(self) when this is just a regular error.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Error for Infallible

Source§

fn module_name(&self) -> &str

Source§

fn code(&self) -> u32

Implementors§

Source§

impl Error for oasis_runtime_sdk::dispatcher::Error

Source§

impl Error for oasis_runtime_sdk::history::Error

Source§

impl Error for oasis_runtime_sdk::modules::access::Error

Source§

impl Error for oasis_runtime_sdk::modules::accounts::Error

Source§

impl Error for oasis_runtime_sdk::modules::consensus::Error

Source§

impl Error for oasis_runtime_sdk::modules::consensus_accounts::Error

Source§

impl Error for oasis_runtime_sdk::modules::core::Error

Source§

impl Error for oasis_runtime_sdk::modules::rewards::Error

Source§

impl Error for oasis_runtime_sdk::modules::rofl::Error

Source§

impl Error for oasis_runtime_sdk::schedule_control::Error

Source§

impl Error for TxSimulationFailure