Expand description
Error types for commerce operations.
This module provides comprehensive error handling for all commerce operations. Errors are organized into a two-level hierarchy:
CommerceError— top-level error that all operations return. It composes domain-specific sub-errors via#[from]conversions.- Domain errors —
OrderError,InventoryError,CustomerError,ProductError,ReturnError,PaymentError,ShippingError— finer-grained errors for use within domain-specific code.
§Using domain errors
New code should prefer returning domain-specific errors when possible. They
convert into CommerceError automatically via From impls:
use stateset_core::errors::{OrderError, CommerceError};
use uuid::Uuid;
fn find_order(id: Uuid) -> Result<(), CommerceError> {
Err(OrderError::not_found(id).into())
}§Generic state transition errors
All state machines share StateTransitionError<S> for invalid transitions:
use stateset_core::errors::StateTransitionError;
#[derive(Debug, Clone, Copy)]
enum Light { Red, Green }
impl std::fmt::Display for Light {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
let err = StateTransitionError::new(Light::Red, Light::Green);
assert!(err.to_string().contains("Red"));§Error categorization
use stateset_core::{CommerceError, Result};
fn process_order(id: uuid::Uuid) -> Result<()> {
Err(CommerceError::OrderNotFound(id))
}
match process_order(uuid::Uuid::new_v4()) {
Err(e) if e.is_not_found() => println!("Not found: {}", e),
Err(e) if e.is_database() => println!("Database error: {}", e),
Err(e) => println!("Other error: {}", e),
Ok(()) => println!("Success"),
}Re-exports§
pub use transition::GotExpected;pub use transition::StateTransitionError;
Modules§
- result
- Per-domain result type aliases for focused error handling.
- transition
- Generic state transition error.
Structs§
- Batch
Error - Error information for a single item in a batch operation.
- Batch
Result - Result of a batch operation that allows partial success.
Enums§
- Batch
Error Code - Categorized batch error codes for programmatic handling.
- Commerce
Error - Main error type for commerce operations.
- Customer
Error - Errors specific to customer operations.
- DbError
- Specific database error types with context.
- Inventory
Error - Errors specific to inventory operations.
- Order
Error - Errors specific to order operations.
- Payment
Error - Errors specific to payment operations.
- Product
Error - Errors specific to product operations.
- Return
Error - Errors specific to return/RMA operations.
- Shipping
Error - Errors specific to shipping and shipment operations.
Constants§
- MAX_
BATCH_ SIZE - Maximum items allowed per batch operation.
Functions§
- validate_
batch_ size - Validate batch size against maximum limit.
- validate_
currency_ code - Validate a currency code (ISO 4217 format).
- validate_
email - Validate an email address format.
- validate_
phone - Validate a phone number format (basic validation).
- validate_
postal_ code - Validate a postal/ZIP code format (basic validation).
- validate_
price - Validate a price/amount value.
- validate_
quantity - Validate a quantity value.
- validate_
required_ text - Validate a required text field for non-empty content and length.
- validate_
required_ uuid - Validate that a UUID is not the nil (all-zero) value.
- validate_
sku - Validate a SKU format.
Type Aliases§
- Result
- Result type alias for commerce operations.