#[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>,
    },
}
Expand description

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)

This enum is marked as 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.

GenericErr

Fields

msg: String
backtrace: Option<Backtrace>

Whenever there is no specific error type available

InvalidBase64

Fields

msg: String
backtrace: Option<Backtrace>

InvalidUtf8

Fields

msg: String
backtrace: Option<Backtrace>

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

NotFound

Fields

kind: String
backtrace: Option<Backtrace>

ParseErr

Fields

target: String

the target type that was attempted

msg: String
backtrace: Option<Backtrace>

SerializeErr

Fields

source: String

the source type that was attempted

msg: String
backtrace: Option<Backtrace>

Unauthorized

Fields

backtrace: Option<Backtrace>

Underflow

Fields

minuend: String
subtrahend: String
backtrace: Option<Backtrace>

Implementations

Trait Implementations

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

👎 Deprecated since 1.42.0:

use the Display impl or to_string()

👎 Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

The lower-level source of this error, if any. Read more

🔬 This is a nightly-only experimental API. (backtrace)

Returns a stack backtrace, if available, of where this error occurred. Read more

Returns a Backtrace that may be printed.

The name of the generated JSON Schema. Read more

Generates a JSON Schema for this type. Read more

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more

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.

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

For maximum effectiveness, this needs to be called as a method to benefit from Rust’s automatic dereferencing of method receivers. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.