Skip to main content

razeri_plugin_api/
error.rs

1// Copyright (C) 2026 Gabriel Shea <gshea@ideapivot.com> - All Rights Reserved
2
3//! Error types for Razeri plugin API.
4
5use thiserror::Error;
6
7/// Errors from storage provider operations.
8#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum StorageError {
11    /// Storage configuration is missing or invalid.
12    #[error("storage configuration error: {0}")]
13    ConfigError(String),
14    /// An I/O error occurred during a storage operation.
15    #[error("storage I/O error: {0}")]
16    IoError(String),
17    /// The requested storage provider is not registered.
18    #[error("storage provider not found: {0}")]
19    ProviderNotFound(String),
20}
21
22/// Errors from LLM client operations.
23#[derive(Debug, Error)]
24#[non_exhaustive]
25pub enum LlmError {
26    /// An HTTP transport error occurred.
27    #[error("HTTP error: {0}")]
28    HttpError(String),
29    /// The response body could not be parsed as JSON.
30    #[error("JSON parse error: {0}")]
31    JsonError(String),
32    /// The provider returned a non-success HTTP status.
33    #[error("provider error (status {status}): {message}")]
34    ProviderError {
35        /// HTTP status code returned by the provider.
36        status: u16,
37        /// Error message from the provider.
38        message: String,
39    },
40    /// The requested LLM provider is not registered.
41    #[error("unsupported provider: {0}")]
42    UnsupportedProvider(String),
43    /// An API key is required but was not configured.
44    #[error("missing API key for provider: {0}")]
45    MissingApiKey(String),
46    /// The response format did not match the expected schema.
47    #[error("unexpected response format: {0}")]
48    UnexpectedFormat(String),
49}
50
51impl LlmError {
52    /// Returns `true` for errors that may succeed on retry (connection drops,
53    /// server overload, etc.).
54    #[must_use]
55    pub fn is_transient(&self) -> bool {
56        match self {
57            LlmError::HttpError(_) => true,
58            LlmError::ProviderError { status, .. } => matches!(status, 429 | 502 | 503 | 504),
59            _ => false,
60        }
61    }
62}
63
64/// Errors from event sink operations.
65#[derive(Debug, Error)]
66#[non_exhaustive]
67pub enum EventSinkError {
68    /// A generic event sink error.
69    #[error("event sink error: {0}")]
70    SinkError(String),
71    /// The event sink could not connect to its backend.
72    #[error("event sink connection failed: {0}")]
73    ConnectionFailed(String),
74}
75
76/// Errors from language renderer operations.
77#[derive(Debug, Error)]
78#[non_exhaustive]
79pub enum LanguageError {
80    /// A rendering error occurred for the target language.
81    #[error("language rendering error: {0}")]
82    RenderError(String),
83    /// The requested language feature is not supported by this renderer.
84    #[error("unsupported language feature: {0}")]
85    UnsupportedFeature(String),
86}