Module error

Module error 

Source
Expand description

Error types for LLM operations.

This module provides structured error handling for multi-llm operations, including categorization, severity levels, and retry guidance.

§Error Types

The main error type is LlmError, which covers all failure modes:

  • Configuration errors (missing API keys, invalid settings)
  • Request failures (network issues, provider errors)
  • Rate limiting and timeouts
  • Authentication failures
  • Token limit exceeded
  • Tool execution failures

§Error Handling Example

use multi_llm::{LlmError, LlmResult};

fn handle_error(err: LlmError) {
    // Check if we should retry
    if err.is_retryable() {
        println!("Retryable error: {}", err);
        // Implement retry logic...
    }

    // Get user-friendly message
    let user_msg = err.user_message();
    println!("Tell user: {}", user_msg);

    // Check error category for routing
    match err.category() {
        multi_llm::error::ErrorCategory::Transient => {
            println!("Temporary issue, try again later");
        }
        multi_llm::error::ErrorCategory::Client => {
            println!("Fix the request and try again");
        }
        _ => {
            println!("System issue, contact support");
        }
    }
}

§Result Type

Use LlmResult<T> as a convenient alias for Result<T, LlmError>:

use multi_llm::LlmResult;

fn my_function() -> LlmResult<String> {
    Ok("Success".to_string())
}

Enums§

ErrorCategory
High-level categorization of errors for routing and handling decisions.
ErrorSeverity
Severity level for logging and alerting decisions.
LlmError
Errors that can occur during LLM operations.
UserErrorCategory
User-facing error categories for conversation flow control.

Type Aliases§

LlmResult
Convenient result type for LLM operations.