opentelemetry_sdk/logs/
error.rs

1use crate::ExportError;
2
3use std::{sync::PoisonError, time::Duration};
4use thiserror::Error;
5
6/// Describe the result of operations in log SDK.
7pub type LogResult<T> = Result<T, LogError>;
8
9#[derive(Error, Debug)]
10#[non_exhaustive]
11/// Errors returned by the log SDK.
12pub enum LogError {
13    /// Export failed with the error returned by the exporter.
14    #[error("Exporter {0} encountered the following errors: {name}", name = .0.exporter_name())]
15    ExportFailed(Box<dyn ExportError>),
16
17    /// Export failed to finish after certain period and processor stopped the export.
18    #[error("Exporter timed out after {} seconds", .0.as_secs())]
19    ExportTimedOut(Duration),
20
21    /// Processor is already shutdown
22    #[error("{0} already shutdown")]
23    AlreadyShutdown(String),
24
25    /// Mutex lock poisoning
26    #[error("mutex lock poisioning for {0}")]
27    MutexPoisoned(String),
28
29    /// Other errors propagated from log SDK that weren't covered above.
30    #[error(transparent)]
31    Other(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
32}
33
34impl<T> From<T> for LogError
35where
36    T: ExportError,
37{
38    fn from(err: T) -> Self {
39        LogError::ExportFailed(Box::new(err))
40    }
41}
42
43impl From<String> for LogError {
44    fn from(err_msg: String) -> Self {
45        LogError::Other(Box::new(Custom(err_msg)))
46    }
47}
48
49impl From<&'static str> for LogError {
50    fn from(err_msg: &'static str) -> Self {
51        LogError::Other(Box::new(Custom(err_msg.into())))
52    }
53}
54
55impl<T> From<PoisonError<T>> for LogError {
56    fn from(err: PoisonError<T>) -> Self {
57        LogError::Other(err.to_string().into())
58    }
59}
60/// Wrap type for string
61#[derive(Error, Debug)]
62#[error("{0}")]
63struct Custom(String);