duende_observe/
error.rs

1//! Observability error types.
2
3/// Result type alias for observe operations.
4pub type Result<T> = std::result::Result<T, ObserveError>;
5
6/// Observability errors.
7#[derive(Debug, thiserror::Error)]
8pub enum ObserveError {
9    /// Tracer error.
10    #[error("tracer error: {0}")]
11    Tracer(String),
12
13    /// Monitor error.
14    #[error("monitor error: {0}")]
15    Monitor(String),
16
17    /// Export error.
18    #[error("export error: {0}")]
19    Export(String),
20
21    /// I/O error.
22    #[error("I/O error: {0}")]
23    Io(#[from] std::io::Error),
24}
25
26impl ObserveError {
27    /// Creates a tracer error.
28    #[must_use]
29    pub fn tracer(msg: impl Into<String>) -> Self {
30        Self::Tracer(msg.into())
31    }
32
33    /// Creates a monitor error.
34    #[must_use]
35    pub fn monitor(msg: impl Into<String>) -> Self {
36        Self::Monitor(msg.into())
37    }
38
39    /// Creates an export error.
40    #[must_use]
41    pub fn export(msg: impl Into<String>) -> Self {
42        Self::Export(msg.into())
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_tracer_error() {
52        let err = ObserveError::tracer("ptrace failed");
53        assert!(err.to_string().contains("tracer error"));
54        assert!(err.to_string().contains("ptrace failed"));
55    }
56
57    #[test]
58    fn test_monitor_error() {
59        let err = ObserveError::monitor("collection failed");
60        assert!(err.to_string().contains("monitor error"));
61        assert!(err.to_string().contains("collection failed"));
62    }
63
64    #[test]
65    fn test_export_error() {
66        let err = ObserveError::export("OTLP connection refused");
67        assert!(err.to_string().contains("export error"));
68        assert!(err.to_string().contains("OTLP"));
69    }
70
71    #[test]
72    fn test_io_error_conversion() {
73        let io_err = std::io::Error::new(std::io::ErrorKind::BrokenPipe, "pipe broken");
74        let err: ObserveError = io_err.into();
75        assert!(err.to_string().contains("I/O error"));
76    }
77}