Skip to main content

Module errors

Module errors 

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

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

BatchError
Error information for a single item in a batch operation.
BatchResult
Result of a batch operation that allows partial success.

Enums§

BatchErrorCode
Categorized batch error codes for programmatic handling.
CommerceError
Main error type for commerce operations.
CustomerError
Errors specific to customer operations.
DbError
Specific database error types with context.
InventoryError
Errors specific to inventory operations.
OrderError
Errors specific to order operations.
PaymentError
Errors specific to payment operations.
ProductError
Errors specific to product operations.
ReturnError
Errors specific to return/RMA operations.
ShippingError
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.