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
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
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
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
impl SdkError
Sourcepub fn code(&self) -> &'static str
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.
Sourcepub fn revert_reason(&self) -> Option<String>
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):
- Borsh-encoded
String—[len:u32_le][utf8 bytes](what the#[pyde::entry]macro emits when an entry panics or callspyde::revert). - Length-prefixed
u64—[len:u64_le][utf8 bytes](legacy emitter shape some hand-written contracts still use). - Raw UTF-8 — fallback for contracts that emit revert reasons without any length prefix.
Sourcepub fn error_code(&self) -> Option<ErrorCode>
pub fn error_code(&self) -> Option<ErrorCode>
For revert errors, scan the revert payload for a HOST_FN_ABI §4 code.
Two extraction paths:
- Named token — the message contains an exact
ERR_*token (e.g."ERR_FORBIDDEN"). The engine’spyde::reverthelpers and the otigen runtime emit this shape. - 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.
Sourcepub fn revert_category(&self) -> Option<&RevertCategory>
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 */,
}Sourcepub fn is_engine_validation_revert(&self) -> bool
pub fn is_engine_validation_revert(&self) -> bool
true iff this revert error carries
category == EngineValidation (nonce, balance, fee,
access-list, dispatch decode).
Sourcepub fn is_contract_revert(&self) -> bool
pub fn is_contract_revert(&self) -> bool
true iff this revert error carries category == Contract
(contract code called revert(msg)).
Sourcepub fn is_vm_trap(&self) -> bool
pub fn is_vm_trap(&self) -> bool
true iff this revert error carries category == Vm
(wasmtime trap, OOB memory, executor-side gas exhaustion).
Sourcepub fn from_receipt(receipt: &Receipt) -> Option<Self>
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 Error for SdkError
impl Error for SdkError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for SdkError
impl RefUnwindSafe for SdkError
impl Send for SdkError
impl Sync for SdkError
impl Unpin for SdkError
impl UnsafeUnpin for SdkError
impl UnwindSafe for SdkError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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