llm_observatory_core/
error.rs

1// Copyright 2025 LLM Observatory Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4//! Error types for LLM Observatory.
5
6/// Result type alias using LLM Observatory's Error type.
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// Error types for LLM Observatory operations.
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12    /// Configuration error
13    #[error("Configuration error: {0}")]
14    Config(String),
15
16    /// Provider error
17    #[error("Provider error: {0}")]
18    Provider(String),
19
20    /// Storage error
21    #[error("Storage error: {0}")]
22    Storage(String),
23
24    /// Serialization/deserialization error
25    #[error("Serialization error: {0}")]
26    Serialization(#[from] serde_json::Error),
27
28    /// OpenTelemetry error
29    #[error("OpenTelemetry error: {0}")]
30    OpenTelemetry(String),
31
32    /// Authentication error
33    #[error("Authentication error: {0}")]
34    Auth(String),
35
36    /// Not found error
37    #[error("Resource not found: {0}")]
38    NotFound(String),
39
40    /// Invalid input error
41    #[error("Invalid input: {0}")]
42    InvalidInput(String),
43
44    /// Internal error
45    #[error("Internal error: {0}")]
46    Internal(String),
47
48    /// IO error
49    #[error("IO error: {0}")]
50    Io(#[from] std::io::Error),
51}
52
53impl Error {
54    /// Create a configuration error.
55    pub fn config(msg: impl Into<String>) -> Self {
56        Self::Config(msg.into())
57    }
58
59    /// Create a provider error.
60    pub fn provider(msg: impl Into<String>) -> Self {
61        Self::Provider(msg.into())
62    }
63
64    /// Create a storage error.
65    pub fn storage(msg: impl Into<String>) -> Self {
66        Self::Storage(msg.into())
67    }
68
69    /// Create an authentication error.
70    pub fn auth(msg: impl Into<String>) -> Self {
71        Self::Auth(msg.into())
72    }
73
74    /// Create a not found error.
75    pub fn not_found(msg: impl Into<String>) -> Self {
76        Self::NotFound(msg.into())
77    }
78
79    /// Create an invalid input error.
80    pub fn invalid_input(msg: impl Into<String>) -> Self {
81        Self::InvalidInput(msg.into())
82    }
83
84    /// Create an internal error.
85    pub fn internal(msg: impl Into<String>) -> Self {
86        Self::Internal(msg.into())
87    }
88}