Skip to main content

CommerceError

Enum CommerceError 

Source
#[non_exhaustive]
pub enum CommerceError {
Show 38 variants OrderNotFound(Uuid), OrderCannotBeCancelled(String), OrderCannotBeRefunded(String), InvalidOrderStatusTransition { from: String, to: String, }, InventoryItemNotFound(String), InsufficientStock { sku: String, requested: String, available: String, }, ReservationNotFound(Uuid), ReservationExpired(Uuid), DuplicateSku(String), CustomerNotFound(Uuid), EmailAlreadyExists(String), CustomerNotActive, ProductNotFound(Uuid), ProductVariantNotFound(Uuid), DuplicateSlug(String), ProductNotPurchasable, ReturnNotFound(Uuid), ReturnCannotBeApproved(String), ReturnPeriodExpired, ItemNotEligibleForReturn, ValidationError(String), InvalidInput { field: String, message: String, }, DatabaseError(String), Database(DbError), NotFound, Conflict(String), OptimisticLockFailure, VersionConflict { entity: String, id: String, expected_version: i32, }, ExternalServiceError(String), Order(OrderError), Inventory(InventoryError), Customer(CustomerError), Product(ProductError), Return(ReturnError), Payment(PaymentError), Shipping(ShippingError), Internal(String), NotPermitted(String),
}
Expand description

Main error type for commerce operations.

This is the top-level error that all public APIs return. Domain-specific sub-errors (OrderError, InventoryError, etc.) convert into this type via From impls, so callers can work with a uniform result type while domain code uses precise error types internally.

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

OrderNotFound(Uuid)

Order with given ID was not found.

§

OrderCannotBeCancelled(String)

Order cannot be cancelled in its current status.

§

OrderCannotBeRefunded(String)

Order cannot be refunded.

§

InvalidOrderStatusTransition

Invalid status transition for an order.

Fields

§from: String

The current status.

§to: String

The requested new status.

§

InventoryItemNotFound(String)

Inventory item not found by SKU or ID.

§

InsufficientStock

Insufficient stock for the requested quantity.

Fields

§sku: String

The SKU that has insufficient stock.

§requested: String

The quantity that was requested.

§available: String

The quantity that is available.

§

ReservationNotFound(Uuid)

Inventory reservation not found.

§

ReservationExpired(Uuid)

Inventory reservation has expired.

§

DuplicateSku(String)

Duplicate SKU already exists.

§

CustomerNotFound(Uuid)

Customer with given ID was not found.

§

EmailAlreadyExists(String)

Email address is already registered.

§

CustomerNotActive

Customer account is not active.

§

ProductNotFound(Uuid)

Product with given ID was not found.

§

ProductVariantNotFound(Uuid)

Product variant with given ID was not found.

§

DuplicateSlug(String)

Duplicate product slug already exists.

§

ProductNotPurchasable

Product is not available for purchase.

§

ReturnNotFound(Uuid)

Return with given ID was not found.

§

ReturnCannotBeApproved(String)

Return cannot be approved in its current status.

§

ReturnPeriodExpired

Return period has expired.

§

ItemNotEligibleForReturn

Item is not eligible for return.

§

ValidationError(String)

General validation error.

§

InvalidInput

Invalid input for a specific field.

Fields

§field: String

The field that has invalid input.

§message: String

The validation error message.

§

DatabaseError(String)

Legacy database error (for backwards compatibility).

§

Database(DbError)

Typed database error with context.

§

NotFound

Generic record not found.

§

Conflict(String)

Conflict during operation.

§

OptimisticLockFailure

Optimistic locking failure.

§

VersionConflict

Version conflict during update.

Fields

§entity: String

The entity type (e.g., “order”, “customer”).

§id: String

The entity ID.

§expected_version: i32

The expected version that was not found.

§

ExternalServiceError(String)

External service (payment, shipping, etc.) failed.

§

Order(OrderError)

Order-domain error.

§

Inventory(InventoryError)

Inventory-domain error.

§

Customer(CustomerError)

Customer-domain error.

§

Product(ProductError)

Product-domain error.

§

Return(ReturnError)

Return-domain error.

§

Payment(PaymentError)

Payment-domain error.

§

Shipping(ShippingError)

Shipping-domain error.

§

Internal(String)

Internal error.

§

NotPermitted(String)

Operation not permitted.

Implementations§

Source§

impl CommerceError

Source

pub const fn is_not_found(&self) -> bool

Check if error is a not found error.

Source

pub const fn is_validation(&self) -> bool

Check if error is a validation error.

Source

pub const fn is_conflict(&self) -> bool

Check if error is a conflict error.

Source

pub const fn is_database(&self) -> bool

Check if error is a database error.

Source

pub const fn is_external_service(&self) -> bool

Check if error is an external service error.

Source

pub const fn is_retryable(&self) -> bool

Check if error is retryable.

Retryable errors include:

  • Connection failures
  • Pool exhaustion
  • Transaction failures (some)
  • Optimistic lock failures
Source

pub const fn is_transient(&self) -> bool

Check if error is transient (temporary failures that may resolve on retry).

This is a superset of is_retryable — it also includes external service failures which may recover after a delay.

Source

pub const fn is_client_error(&self) -> bool

Check if error is a client error (bad input from the caller).

Client errors include not-found, validation, conflict, and permission errors.

Source

pub const fn is_server_error(&self) -> bool

Check if error is a server error (internal / infrastructure failures).

Server errors include database errors, internal errors, and external service failures.

Source

pub const fn is_not_permitted(&self) -> bool

Check if this is a permission-denied error.

Source

pub const fn suggested_status_code(&self) -> u16

Suggest an HTTP status code for this error.

Useful for API layers that need to map domain errors to HTTP responses.

§Example
use stateset_core::CommerceError;

let err = CommerceError::NotFound;
assert_eq!(err.suggested_status_code(), 404);

let err = CommerceError::ValidationError("bad".into());
assert_eq!(err.suggested_status_code(), 400);
Source

pub const fn as_db_error(&self) -> Option<&DbError>

Get the underlying database error if this is a database error.

Source

pub const fn as_order_error(&self) -> Option<&OrderError>

Get the underlying order error if this is an order error.

Source

pub const fn as_inventory_error(&self) -> Option<&InventoryError>

Get the underlying inventory error if this is an inventory error.

Source

pub const fn as_customer_error(&self) -> Option<&CustomerError>

Get the underlying customer error if this is a customer error.

Source

pub const fn as_product_error(&self) -> Option<&ProductError>

Get the underlying product error if this is a product error.

Source

pub const fn db(error: DbError) -> CommerceError

Create a database error from a typed DbError.

Source

pub fn query_failed( table: &'static str, operation: &'static str, message: impl Into<String>, ) -> CommerceError

Create a query failed error with context.

Source

pub fn constraint_violation( table: &'static str, constraint: impl Into<String>, message: impl Into<String>, ) -> CommerceError

Create a constraint violation error.

Source

pub fn connection_failed( url: impl Into<String>, message: impl Into<String>, ) -> CommerceError

Create a connection failed error.

Trait Implementations§

Source§

impl Debug for CommerceError

Source§

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

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

impl Display for CommerceError

Source§

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

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

impl Error for CommerceError

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 #99301)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<CustomerError> for CommerceError

Source§

fn from(source: CustomerError) -> CommerceError

Converts to this type from the input type.
Source§

impl From<DbError> for CommerceError

Source§

fn from(source: DbError) -> CommerceError

Converts to this type from the input type.
Source§

impl From<InventoryError> for CommerceError

Source§

fn from(source: InventoryError) -> CommerceError

Converts to this type from the input type.
Source§

impl From<MaintenanceError> for CommerceError

Source§

fn from(err: MaintenanceError) -> CommerceError

Converts to this type from the input type.
Source§

impl From<OrderError> for CommerceError

Source§

fn from(source: OrderError) -> CommerceError

Converts to this type from the input type.
Source§

impl From<PaymentError> for CommerceError

Source§

fn from(source: PaymentError) -> CommerceError

Converts to this type from the input type.
Source§

impl From<ProductError> for CommerceError

Source§

fn from(source: ProductError) -> CommerceError

Converts to this type from the input type.
Source§

impl From<ReturnError> for CommerceError

Source§

fn from(source: ReturnError) -> CommerceError

Converts to this type from the input type.
Source§

impl From<ShippingError> for CommerceError

Source§

fn from(source: ShippingError) -> CommerceError

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: 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> 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