Skip to main content

langfuse_core/
error.rs

1//! Error types for the Langfuse SDK.
2
3/// Primary error type for all Langfuse operations.
4#[derive(thiserror::Error, Debug)]
5pub enum LangfuseError {
6    /// Configuration error.
7    #[error("Configuration error: {0}")]
8    Config(#[from] ConfigError),
9
10    /// API returned an error response.
11    #[error("API error: {status} - {message}")]
12    Api {
13        /// HTTP status code.
14        status: u16,
15        /// Error message from the API.
16        message: String,
17    },
18
19    /// Authentication failed (401).
20    #[error("Authentication failed")]
21    Auth,
22
23    /// Network-level error.
24    #[error("Network error: {0}")]
25    Network(#[from] reqwest::Error),
26
27    /// Serialization/deserialization error.
28    #[error("Serialization error: {0}")]
29    Serialization(#[from] serde_json::Error),
30
31    /// Requested prompt was not found.
32    #[error("Prompt not found: {name}")]
33    PromptNotFound {
34        /// Name of the prompt that was not found.
35        name: String,
36    },
37
38    /// Prompt template compilation failed due to a missing variable.
39    #[error("Prompt compilation error: missing variable '{variable}'")]
40    PromptCompilation {
41        /// Name of the missing template variable.
42        variable: String,
43    },
44
45    /// Media upload or processing error.
46    #[error("Media error: {0}")]
47    Media(String),
48
49    /// OpenTelemetry pipeline error.
50    #[error("OpenTelemetry error: {0}")]
51    Otel(String),
52}
53
54/// Configuration-specific errors.
55#[derive(thiserror::Error, Debug)]
56pub enum ConfigError {
57    /// A required configuration field was not provided.
58    #[error("Missing required configuration: {field}")]
59    MissingField {
60        /// Name of the missing configuration field.
61        field: String,
62    },
63
64    /// A configuration field had an invalid value.
65    #[error("Invalid configuration value for '{field}': {message}")]
66    InvalidValue {
67        /// Name of the invalid field.
68        field: String,
69        /// Description of why the value is invalid.
70        message: String,
71    },
72}
73
74/// Convenience result type for Langfuse operations.
75pub type Result<T> = std::result::Result<T, LangfuseError>;