Skip to main content

ErrorCode

Trait ErrorCode 

Source
pub trait ErrorCode {
    // Required methods
    fn code(&self) -> &'static str;
    fn is_recoverable(&self) -> bool;
}
Expand description

Unified error code interface for ORCS errors.

Implement this trait for all error types to enable:

  • Consistent error code format across crates
  • Unified error handling in EventBus and components
  • Standardized logging and monitoring

§Code Format

Error codes should be:

  • UPPER_SNAKE_CASE: e.g., "TIMEOUT", "PERMISSION_DENIED"
  • Namespace-prefixed for specificity: e.g., "AUTH_EXPIRED", "EVENT_INVALID_SIGNAL"
  • Stable: Codes should not change once defined (API contract)

§Recoverability

An error is recoverable if:

  • Retrying the operation may succeed
  • The user can take action to fix it
  • It’s a transient condition (network, timeout)

Non-recoverable errors:

  • Invalid input (won’t change on retry)
  • Permission denied (requires elevation, not retry)
  • Internal errors (bugs)

§Example Implementation

use orcs_types::ErrorCode;

enum AuthError {
    SessionExpired,
    PermissionDenied { action: String },
    InvalidToken,
}

impl ErrorCode for AuthError {
    fn code(&self) -> &'static str {
        match self {
            Self::SessionExpired => "AUTH_SESSION_EXPIRED",
            Self::PermissionDenied { .. } => "AUTH_PERMISSION_DENIED",
            Self::InvalidToken => "AUTH_INVALID_TOKEN",
        }
    }

    fn is_recoverable(&self) -> bool {
        match self {
            // Session can be refreshed
            Self::SessionExpired => true,
            // Need elevation, not retry
            Self::PermissionDenied { .. } => false,
            // Invalid token won't become valid
            Self::InvalidToken => false,
        }
    }
}

Required Methods§

Source

fn code(&self) -> &'static str

Returns a machine-readable error code.

§Format
  • UPPER_SNAKE_CASE
  • Optionally prefixed with domain (e.g., "AUTH_", "EVENT_")
  • Stable across versions (breaking change if modified)
§Examples
  • "TIMEOUT"
  • "PERMISSION_DENIED"
  • "AUTH_SESSION_EXPIRED"
  • "EVENT_INVALID_SIGNAL"
Source

fn is_recoverable(&self) -> bool

Returns whether the error is recoverable.

§Returns
  • true: Retry may succeed, or user can take corrective action
  • false: Retry will not help, requires code/config change

Implementors§