razeri-plugin-api 0.18.0

Extension traits and registries for Razeri plugins
Documentation
// Copyright (C) 2026 Gabriel Shea
// Licensed under either of the Apache License, Version 2.0 or the MIT
// license, at your option.

//! Error types for Razeri plugin API.

use thiserror::Error;

/// Errors from storage provider operations.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum StorageError {
    /// Storage configuration is missing or invalid.
    #[error("storage configuration error: {0}")]
    ConfigError(String),
    /// An I/O error occurred during a storage operation.
    #[error("storage I/O error: {0}")]
    IoError(String),
    /// The requested storage provider is not registered.
    #[error("storage provider not found: {0}")]
    ProviderNotFound(String),
}

/// Errors from LLM client operations.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum LlmError {
    /// An HTTP transport error occurred.
    #[error("HTTP error: {0}")]
    HttpError(String),
    /// The response body could not be parsed as JSON.
    #[error("JSON parse error: {0}")]
    JsonError(String),
    /// The provider returned a non-success HTTP status.
    #[error("provider error (status {status}): {message}")]
    ProviderError {
        /// HTTP status code returned by the provider.
        status: u16,
        /// Error message from the provider.
        message: String,
    },
    /// The requested LLM provider is not registered.
    #[error("unsupported provider: {0}")]
    UnsupportedProvider(String),
    /// An API key is required but was not configured.
    #[error("missing API key for provider: {0}")]
    MissingApiKey(String),
    /// The response format did not match the expected schema.
    #[error("unexpected response format: {0}")]
    UnexpectedFormat(String),
}

impl LlmError {
    /// Returns `true` for errors that may succeed on retry (connection drops,
    /// server overload, etc.).
    #[must_use]
    pub fn is_transient(&self) -> bool {
        match self {
            LlmError::HttpError(_) => true,
            LlmError::ProviderError { status, .. } => matches!(status, 429 | 502 | 503 | 504),
            _ => false,
        }
    }
}

/// Errors from event sink operations.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum EventSinkError {
    /// A generic event sink error.
    #[error("event sink error: {0}")]
    SinkError(String),
    /// The event sink could not connect to its backend.
    #[error("event sink connection failed: {0}")]
    ConnectionFailed(String),
}

/// Errors from language renderer operations.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum LanguageError {
    /// A rendering error occurred for the target language.
    #[error("language rendering error: {0}")]
    RenderError(String),
    /// The requested language feature is not supported by this renderer.
    #[error("unsupported language feature: {0}")]
    UnsupportedFeature(String),
}