Skip to main content

Error

Trait Error 

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

    // Provided method
    fn to_execution_result(&self) -> ExecutionResult { ... }
}
Expand description

A contract 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:

#[derive(Clone, Debug, Error, thiserror::Error)]
#[sdk_error(autonumber)]
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 to_execution_result(&self) -> ExecutionResult

Converts the error into an execution result.

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§