Skip to main content

dig_logging/
error.rs

1//! The crate's public error type.
2
3use std::io;
4use std::path::PathBuf;
5
6/// Everything that can go wrong initializing logging or running a `logs` verb.
7#[derive(Debug, thiserror::Error)]
8pub enum Error {
9    /// The resolved log directory could not be created or written.
10    #[error("could not create or write the log directory {path}: {source}")]
11    LogDir {
12        /// The directory dig-logging tried to use.
13        path: PathBuf,
14        /// The underlying filesystem error.
15        source: io::Error,
16    },
17
18    /// The rolling file appender could not be built for the resolved directory.
19    #[error("could not open the rolling log file in {path}: {source}")]
20    Appender {
21        /// The directory the appender targeted.
22        path: PathBuf,
23        /// The underlying appender error.
24        source: tracing_appender::rolling::InitError,
25    },
26
27    /// A level-filter directive (default, env, persisted, or a runtime reload) was not valid.
28    #[error("invalid log filter directive {directive:?}: {message}")]
29    Filter {
30        /// The rejected directive text.
31        directive: String,
32        /// Why it was rejected.
33        message: String,
34    },
35
36    /// A global subscriber was already installed (init called twice, or another crate set one).
37    #[error("a tracing subscriber is already installed; dig_logging::init must be called once")]
38    AlreadyInitialized,
39
40    /// A `logs` verb hit a plain I/O error (reading a log file, writing a bundle).
41    #[error(transparent)]
42    Io(#[from] io::Error),
43
44    /// Serializing a bundle manifest failed.
45    #[error("could not serialize the bundle manifest: {0}")]
46    Manifest(#[from] serde_json::Error),
47
48    /// Writing the bundle zip archive failed.
49    #[error("could not write the log bundle: {0}")]
50    Bundle(#[from] zip::result::ZipError),
51}
52
53/// The crate's result alias.
54pub type Result<T> = std::result::Result<T, Error>;