Skip to main content

SdkError

Enum SdkError 

Source
pub enum SdkError {
    Rpc(String),
    Connection(String),
    Signing(String),
    Timeout(String),
    Reverted {
        gas_used: u64,
        data: Vec<u8>,
        reason: Option<RevertReason>,
    },
    InsufficientBalance {
        required: u128,
        available: u128,
    },
    HostFn {
        code: ErrorCode,
        message: String,
    },
    InvalidAddress(String),
    InvalidArgument(String),
    InvalidResponse(String),
    Other(String),
}
Expand description

Errors returned from SDK operations.

Each variant carries enough context to surface a useful message to a dapp’s user. See SdkError::code for stable, programmatic codes suitable for client-side error branching.

Variants§

§

Rpc(String)

JSON-RPC error returned by the node (method-level failure).

§

Connection(String)

Transport-layer failure — TCP/TLS handshake, DNS, connection reset.

§

Signing(String)

Local signing failure (FALCON keygen, signature emission).

§

Timeout(String)

A bounded wait elapsed without the expected event (typically used by wait_for_receipt and await_finalized).

§

Reverted

Transaction reverted on-chain. State changes rolled back; gas is still charged per crate::types::ReceiptStatus::Reverted.

reason carries the engine’s structured revert reason when available — Some for any status: "reverted" receipt when the engine emits a structured reason, None when the SDK derived the revert from return_data alone (older nodes / direct constructions). Branch on Self::revert_category for control-flow decisions; use reason.message for display.

Fields

§gas_used: u64

Gas charged before the revert.

§data: Vec<u8>

Return data emitted by pyde::revert(...) (UTF-8 if possible).

§reason: Option<RevertReason>

Structured revert reason from the engine when present. None when the SDK only has the raw data bytes — call Self::revert_reason to decode from data.

§

InsufficientBalance

Sender’s balance is too low to cover value + gas_limit × base_fee. Surfaced both at mempool admission and at execute-time.

Fields

§required: u128

Minimum required (value + gas reservation).

§available: u128

Sender’s actual balance.

§

HostFn

A typed HOST_FN_ABI §4 error code surfaced from a host function or a cross-contract call. Use when the SDK can extract a specific ERR_* code rather than collapsing to the generic SdkError::Reverted / SdkError::Rpc.

Fields

§code: ErrorCode

The structured §4 code.

§message: String

Caller-visible context the SDK / node attached.

§

InvalidAddress(String)

Caller passed a malformed address (wrong length, bad hex, or reserved sentinel).

§

InvalidArgument(String)

Caller passed an argument that failed pre-flight validation.

§

InvalidResponse(String)

Node returned a response the SDK could not deserialize (typically indicates a node-side bug or version skew).

§

Other(String)

Catch-all for errors that don’t fit a structured variant. Prefer adding a new variant over leaning on this.

Implementations§

Source§

impl SdkError

Source

pub fn code(&self) -> &'static str

Stable programmatic code string suitable for client-side branching.

These mirror ethers-rs / alloy conventions so dapp devs can reuse existing error-handling habits.

Source

pub fn revert_reason(&self) -> Option<String>

For revert errors, attempt to decode the human-readable reason the contract author passed to pyde::revert(...). Returns None for non-revert errors or if the revert data isn’t a recognizable encoding.

Recognizes three encodings (probed in order):

  1. Borsh-encoded String — [len:u32_le][utf8 bytes] (what the #[pyde::entry] macro emits when an entry panics or calls pyde::revert).
  2. Length-prefixed u64 — [len:u64_le][utf8 bytes] (legacy emitter shape some hand-written contracts still use).
  3. Raw UTF-8 — fallback for contracts that emit revert reasons without any length prefix.
Source

pub fn error_code(&self) -> Option<ErrorCode>

For revert errors, scan the revert payload for a HOST_FN_ABI §4 code.

Two extraction paths:

  1. Named token — the message contains an exact ERR_* token (e.g. "ERR_FORBIDDEN"). The engine’s pyde::revert helpers and the otigen runtime emit this shape.
  2. Negative integer — the message contains a parseable negative integer in the spec table ("-5", "code: -10").

Returns None for non-revert errors or revert payloads that don’t contain a recognizable code.

Source

pub fn is_revert(&self) -> bool

Convenience: true iff this error is a contract revert.

Source

pub fn revert_category(&self) -> Option<&RevertCategory>

Structured revert category populated by the engine. Returns None for non-revert errors or revert errors constructed from a receipt that didn’t carry a structured reason.

Branch on this — not Self::revert_reason — for control flow:

ⓘ
use pyde_rust_sdk::types::RevertCategory;

match err.revert_category() {
    Some(RevertCategory::EngineValidation) => /* nonce/balance/etc */,
    Some(RevertCategory::Contract)         => /* user's contract said no */,
    Some(RevertCategory::Vm)               => /* trap / OOM / OOG */,
    _                                      => /* not a revert, or older engine */,
}
Source

pub fn is_engine_validation_revert(&self) -> bool

true iff this revert error carries category == EngineValidation (nonce, balance, fee, access-list, dispatch decode).

Source

pub fn is_contract_revert(&self) -> bool

true iff this revert error carries category == Contract (contract code called revert(msg)).

Source

pub fn is_vm_trap(&self) -> bool

true iff this revert error carries category == Vm (wasmtime trap, OOB memory, executor-side gas exhaustion).

Source

pub fn from_receipt(receipt: &Receipt) -> Option<Self>

Construct an SdkError from a Receipt whose status != Success. Returns None for success receipts (which aren’t errors).

Out-of-gas → SdkError::Reverted with synthesised reason Some({category: Vm, message: "out of gas"}). Reverted with structured reason → carried through. Reverted without structured reason → bytes-only.

Trait Implementations§

Source§

impl Debug for SdkError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SdkError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for SdkError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more