1use thiserror::Error;
6
7#[derive(Debug, Error)]
10pub enum TraceError {
11 #[error("missing required env var: {0}")]
13 MissingEnvVar(String),
14
15 #[error("invalid config: {0}")]
17 InvalidConfig(String),
18
19 #[cfg(feature = "langfuse")]
21 #[error("network error sending to {backend}: {source}")]
22 Network {
23 backend: &'static str,
25 #[source]
27 source: reqwest::Error,
28 },
29
30 #[error("backend {backend} returned {status}: {body}")]
32 BackendStatus {
33 backend: &'static str,
35 status: u16,
37 body: String,
39 },
40
41 #[error("queue overflowed; {dropped} events dropped (backend: {backend})")]
43 QueueOverflow {
44 backend: &'static str,
46 dropped: usize,
48 },
49
50 #[error("backend does not support: {0}")]
52 Unsupported(&'static str),
53
54 #[error("serialization: {0}")]
56 Serde(#[from] serde_json::Error),
57}
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn missing_env_var_displays_name() {
65 let e = TraceError::MissingEnvVar("LANGFUSE_PUBLIC_KEY".into());
66 assert_eq!(
67 e.to_string(),
68 "missing required env var: LANGFUSE_PUBLIC_KEY"
69 );
70 }
71
72 #[test]
73 fn unsupported_carries_feature_name() {
74 let e = TraceError::Unsupported("scores");
75 assert_eq!(e.to_string(), "backend does not support: scores");
76 }
77}