Skip to main content

AptosError

Enum AptosError 

Source
pub enum AptosError {
Show 28 variants Http(Error), Json(Error), Bcs(String), Url(ParseError), Hex(FromHexError), InvalidAddress(String), InvalidPublicKey(String), InvalidPrivateKey(String), InvalidSignature(String), SignatureVerificationFailed, InvalidTypeTag(String), Transaction(String), SimulationFailed(String), SubmissionFailed(String), ExecutionFailed { vm_status: String, }, TransactionTimeout { hash: String, timeout_secs: u64, }, Api { status_code: u16, message: String, error_code: Option<String>, vm_error_code: Option<u64>, }, RateLimited { retry_after_secs: Option<u64>, }, NotFound(String), AccountNotFound(String), InvalidMnemonic(String), InvalidJwt(String), KeyDerivation(String), InsufficientSignatures { required: usize, provided: usize, }, FeatureNotEnabled(String), Config(String), Internal(String), Other(Error),
}
Expand description

The main error type for the Aptos SDK.

This enum covers all possible error conditions that can occur when interacting with the Aptos blockchain through this SDK.

Variants§

§

Http(Error)

Error occurred during HTTP communication

§

Json(Error)

Error occurred during JSON serialization/deserialization

§

Bcs(String)

Error occurred during BCS serialization/deserialization

§

Url(ParseError)

Error occurred during URL parsing

§

Hex(FromHexError)

Error occurred during hex encoding/decoding

§

InvalidAddress(String)

Invalid account address

§

InvalidPublicKey(String)

Invalid public key

§

InvalidPrivateKey(String)

Invalid private key

§

InvalidSignature(String)

Invalid signature

§

SignatureVerificationFailed

Signature verification failed

§

InvalidTypeTag(String)

Invalid type tag format

§

Transaction(String)

Transaction building error

§

SimulationFailed(String)

Transaction simulation failed

§

SubmissionFailed(String)

Transaction submission failed

§

ExecutionFailed

Transaction execution failed on chain

Fields

§vm_status: String

The VM status message explaining the failure

§

TransactionTimeout

Transaction timed out waiting for confirmation

Fields

§hash: String

The hash of the transaction that timed out

§timeout_secs: u64

How long we waited before timing out

§

Api

API returned an error response

Fields

§status_code: u16

HTTP status code

§message: String

Error message from the API

§error_code: Option<String>

Optional error code from the API

§vm_error_code: Option<u64>

Optional VM error code

§

RateLimited

Rate limited by the API

Fields

§retry_after_secs: Option<u64>

How long to wait before retrying (if provided)

§

NotFound(String)

Resource not found

§

AccountNotFound(String)

Account not found

§

InvalidMnemonic(String)

Invalid mnemonic phrase

§

InvalidJwt(String)

Invalid JWT

§

KeyDerivation(String)

Key derivation error

§

InsufficientSignatures

Insufficient signatures for multi-signature operation

Fields

§required: usize

Number of signatures required

§provided: usize

Number of signatures provided

§

FeatureNotEnabled(String)

Feature not enabled

§

Config(String)

Configuration error

§

Internal(String)

Internal SDK error (should not happen)

§

Other(Error)

Any other error

Implementations§

Source§

impl AptosError

Source

pub fn bcs<E: Display>(err: E) -> Self

Creates a new BCS error

Source

pub fn transaction<S: Into<String>>(msg: S) -> Self

Creates a new transaction error

Source

pub fn api(status_code: u16, message: impl Into<String>) -> Self

Creates a new API error from response details

Source

pub fn api_with_details( status_code: u16, message: impl Into<String>, error_code: Option<String>, vm_error_code: Option<u64>, ) -> Self

Creates a new API error with additional details

Source

pub fn is_not_found(&self) -> bool

Returns true if this is a “not found” error

Source

pub fn is_timeout(&self) -> bool

Returns true if this is a timeout error

Source

pub fn is_retryable(&self) -> bool

Returns true if this is a transient error that might succeed on retry

Source

pub fn sanitized_message(&self) -> String

Returns a sanitized version of the error message safe for logging.

This method:

  • Removes control characters that could corrupt logs
  • Truncates very long messages to prevent log flooding
  • Redacts patterns that might indicate sensitive information
§Example
use aptos_sdk::AptosError;

let err = AptosError::api(500, "Internal server error with details...");
let safe_msg = err.sanitized_message();
// safe_msg is guaranteed to be safe for logging
Source

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

Returns the error message suitable for display to end users.

This is a more conservative sanitization that provides less detail but is safer for user-facing error messages.

Trait Implementations§

Source§

impl Debug for AptosError

Source§

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

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

impl Display for AptosError

Source§

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

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

impl Error for AptosError

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
Source§

impl From<Error> for AptosError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for AptosError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for AptosError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<FromHexError> for AptosError

Source§

fn from(source: FromHexError) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for AptosError

Source§

fn from(source: ParseError) -> Self

Converts to this type from the input type.

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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