use thiserror::Error;
#[derive(Debug, Error)]
pub enum TraceError {
#[error("missing required env var: {0}")]
MissingEnvVar(String),
#[error("invalid config: {0}")]
InvalidConfig(String),
#[cfg(feature = "langfuse")]
#[error("network error sending to {backend}: {source}")]
Network {
backend: &'static str,
#[source]
source: reqwest::Error,
},
#[error("backend {backend} returned {status}: {body}")]
BackendStatus {
backend: &'static str,
status: u16,
body: String,
},
#[error("queue overflowed; {dropped} events dropped (backend: {backend})")]
QueueOverflow {
backend: &'static str,
dropped: usize,
},
#[error("backend does not support: {0}")]
Unsupported(&'static str),
#[error("serialization: {0}")]
Serde(#[from] serde_json::Error),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn missing_env_var_displays_name() {
let e = TraceError::MissingEnvVar("LANGFUSE_PUBLIC_KEY".into());
assert_eq!(
e.to_string(),
"missing required env var: LANGFUSE_PUBLIC_KEY"
);
}
#[test]
fn unsupported_carries_feature_name() {
let e = TraceError::Unsupported("scores");
assert_eq!(e.to_string(), "backend does not support: scores");
}
}