[][src]Enum cosmwasm_std::StdError

#[non_exhaustive]pub enum StdError {
    GenericErr {
        msg: String,
        backtrace: Option<Backtrace>,
    InvalidBase64 {
        msg: String,
        backtrace: Option<Backtrace>,
    InvalidUtf8 {
        msg: String,
        backtrace: Option<Backtrace>,
    NotFound {
        kind: String,
        backtrace: Option<Backtrace>,
    ParseErr {
        target: String,
        msg: String,
        backtrace: Option<Backtrace>,
    SerializeErr {
        source: String,
        msg: String,
        backtrace: Option<Backtrace>,
    Unauthorized {
        backtrace: Option<Backtrace>,
    Underflow {
        minuend: String,
        subtrahend: String,
        backtrace: Option<Backtrace>,

Structured error type for init, handle and query.

This can be serialized and passed over the Wasm/VM boundary, which allows us to use structured error types in e.g. integration tests. In that process backtraces are stripped off.

The prefix "Std" means "the standard error within the standard library". This is not the only result/error type in cosmwasm-std.

When new cases are added, they should describe the problem rather than what was attempted (e.g. InvalidBase64 is preferred over Base64DecodingErr). In the long run this allows us to get rid of the duplication in "StdError::FooErr".

Checklist for adding a new error:

  • Add enum case
  • Add to PartialEq implementation
  • Add serialize/deserialize test
  • Add creator function in std_error_helpers.rs
  • Regenerate schemas

Variants (Non-exhaustive)

Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.

Whenever there is no specific error type available

Fields of GenericErr

msg: Stringbacktrace: Option<Backtrace>

Fields of InvalidBase64

msg: Stringbacktrace: Option<Backtrace>

Whenever UTF-8 bytes cannot be decoded into a unicode string, e.g. in String::from_utf8 or str::from_utf8.

Fields of InvalidUtf8

msg: Stringbacktrace: Option<Backtrace>

Fields of NotFound

kind: Stringbacktrace: Option<Backtrace>

Fields of ParseErr

target: String

the target type that was attempted

msg: Stringbacktrace: Option<Backtrace>

Fields of SerializeErr

source: String

the source type that was attempted

msg: Stringbacktrace: Option<Backtrace>

Fields of Unauthorized

backtrace: Option<Backtrace>

Fields of Underflow

minuend: Stringsubtrahend: Stringbacktrace: Option<Backtrace>


impl StdError[src]

pub fn generic_err<S: Into<String>>(msg: S) -> Self[src]

pub fn invalid_base64<S: ToString>(msg: S) -> Self[src]

pub fn invalid_utf8<S: ToString>(msg: S) -> Self[src]

pub fn not_found<S: Into<String>>(kind: S) -> Self[src]

pub fn parse_err<T: Into<String>, M: ToString>(target: T, msg: M) -> Self[src]

pub fn serialize_err<S: Into<String>, M: ToString>(source: S, msg: M) -> Self[src]

pub fn underflow<U: ToString>(minuend: U, subtrahend: U) -> Self[src]

pub fn unauthorized() -> Self[src]

Trait Implementations

impl Debug for StdError[src]

impl<'de> Deserialize<'de> for StdError[src]

impl Display for StdError[src]

impl Error for StdError where
    Self: Debug + Display

impl ErrorCompat for StdError[src]

impl JsonSchema for StdError[src]

impl PartialEq<StdError> for StdError[src]

fn eq(&self, other: &Self) -> bool[src]

Two errors are considered equal if and only if their payloads (i.e. all fields other than backtrace) are equal.

The origin of the error (expressed by its backtrace) is ignored, which allows equality checks on errors and results in tests. This is a property that might not always be desired depending on the use case and something you should be aware of.

Note: We destruct the unused backtrace as _ to avoid the use of .. which silently ignores newly added fields.

impl Serialize for StdError[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

impl<T> AsErrorSource for T where
    T: 'static + Error

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> ToString for T where
    T: Display + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.