tauri_plugin_tracing/
error.rs

1//! Error types for the tracing plugin.
2
3use serde::{Serialize, Serializer};
4
5/// A specialized [`Result`](std::result::Result) type for tracing plugin operations.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors that can occur when using the tracing plugin.
9#[derive(Debug, thiserror::Error)]
10#[cfg_attr(feature = "specta", derive(specta::Type))]
11pub enum Error {
12    /// An error from the Tauri runtime.
13    #[error(transparent)]
14    #[cfg_attr(feature = "specta", specta(skip))]
15    Tauri(#[from] tauri::Error),
16
17    /// An I/O error, typically from file operations.
18    #[error(transparent)]
19    #[cfg_attr(feature = "specta", specta(skip))]
20    Io(#[from] std::io::Error),
21
22    /// An error formatting a timestamp.
23    #[error(transparent)]
24    #[cfg_attr(feature = "specta", specta(skip))]
25    TimeFormat(#[from] time::error::Format),
26
27    /// An invalid time format description was provided.
28    #[error(transparent)]
29    #[cfg_attr(feature = "specta", specta(skip))]
30    InvalidFormatDescription(#[from] time::error::InvalidFormatDescription),
31
32    /// The internal logger was not initialized.
33    #[error("Internal logger disabled and cannot be acquired or attached")]
34    LoggerNotInitialized,
35
36    /// Failed to set the global default subscriber.
37    #[error(transparent)]
38    #[cfg_attr(feature = "specta", specta(skip))]
39    SetGlobalDefault(#[from] tracing::subscriber::SetGlobalDefaultError),
40
41    /// The requested feature is not yet implemented.
42    #[error("Not implemented")]
43    NotImplemented,
44
45    /// A mutex lock was poisoned (another thread panicked while holding the lock).
46    #[error("Lock poisoned: {0}")]
47    LockPoisoned(String),
48}
49
50impl Serialize for Error {
51    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
52    where
53        S: Serializer,
54    {
55        serializer.serialize_str(self.to_string().as_ref())
56    }
57}