Skip to main content

Overview

NanoARB uses Rust’s type-safe error handling with the Result type. All errors implement the thiserror::Error trait for consistent error messages and conversions.

Error Type

The core Error enum defines all possible error conditions.

Definition

Result Type

A type alias for convenience.

Error Variants

InvalidPrice

Returned when a price value is invalid.
InvalidPrice
Error
Common causes:
  • Negative prices where not allowed
  • Price exceeds maximum allowed value
  • Invalid price format in parsing

InvalidQuantity

Returned when a quantity value is invalid.
InvalidQuantity
Error
Common causes:
  • Zero quantity for orders
  • Quantity exceeds maximum
  • Invalid quantity format

InvalidOrderId

Returned when an order ID is invalid.
InvalidOrderId
Error

InvalidTimestamp

Returned when a timestamp value is invalid.
InvalidTimestamp
Error
Common causes:
  • Timestamps in the future (when not allowed)
  • Timestamps before Unix epoch (when not allowed)
  • Invalid timestamp format

InvalidInstrument

Returned when an instrument identifier is invalid.
InvalidInstrument
Error
Common causes:
  • Unknown instrument symbol
  • Instrument not configured
  • Invalid instrument ID

OrderNotFound

Returned when an order cannot be found.
OrderNotFound
Error
Common causes:
  • Attempting to cancel non-existent order
  • Querying order that was never created
  • Order ID typo

InsufficientLiquidity

Returned when there’s not enough liquidity to fill an order.
InsufficientLiquidity
Error
Common causes:
  • Market order larger than available liquidity
  • Thin order book
  • Attempting to fill at specific price level with insufficient depth

RiskLimitExceeded

Returned when a risk limit is breached.
RiskLimitExceeded
Error
Common causes:
  • Position limit exceeded
  • Order size too large
  • Drawdown limit breached
  • Daily loss limit hit

ParseError

Returned when parsing fails.
ParseError
Error
Common causes:
  • Invalid data format
  • Malformed configuration
  • Corrupt market data

ConfigError

Returned when configuration is invalid.
ConfigError
Error
Common causes:
  • Missing configuration fields
  • Invalid configuration values
  • Conflicting configuration options

IoError

Returned when I/O operations fail.
IoError
Error
Common causes:
  • File not found
  • Permission denied
  • Disk full
  • Network connection lost

SerializationError

Returned when serialization/deserialization fails.
SerializationError
Error
Common causes:
  • Invalid data format
  • Version mismatch
  • Corrupt data

ModelError

Returned when ML model inference fails.
ModelError
Error
Common causes:
  • Invalid input shape
  • Model not loaded
  • Inference timeout
  • GPU out of memory

Internal

Returned for unexpected internal errors.
Internal
Error
Common causes:
  • Invariant violations
  • Unexpected state
  • Programming errors

Error Handling Patterns

Basic Error Handling

Using the ? Operator

The ? operator propagates errors up the call stack.

Error Context

Add context to errors for better debugging.

Handling Specific Errors

Converting Errors

Standard library errors are automatically converted.

Logging Errors

Custom Error Creation

Best Practices

1. Use Descriptive Error Messages

2. Include Context

3. Handle Errors Appropriately

4. Log Before Returning

5. Use Result Type Consistently