Skip to main content

metrics_exporter_csv/
error.rs

1use std::io;
2
3use metrics::SetRecorderError;
4use thiserror::Error;
5
6use crate::recorder::CsvRecorder;
7
8/// Error type for the CSV exporter.
9///
10/// This is returned by recorder construction and write operations.
11#[derive(Debug, Error)]
12pub enum CsvError {
13    /// I/O failures when creating, opening, or writing the CSV file.
14    #[error(transparent)]
15    Io(#[from] io::Error),
16    /// Async CSV serialization failures.
17    #[error(transparent)]
18    CsvAsyncWriter(#[from] csv_async::Error),
19}
20
21/// Error type for builder and installation operations.
22#[derive(Debug, Error)]
23pub enum BuildError {
24    /// Builder requires an output path via `CsvBuilder::with_path`.
25    #[error("csv output path must be provided with CsvBuilder::with_path")]
26    MissingPath,
27    /// Failures when creating, opening, or writing the CSV file.
28    #[error(transparent)]
29    Csv(#[from] CsvError),
30    /// Failed to install as the global recorder.
31    #[error(transparent)]
32    Install(#[from] SetRecorderError<CsvRecorder>),
33}
34
35#[cfg(test)]
36mod tests {
37    use std::io;
38
39    use super::CsvError;
40
41    #[test]
42    fn io_error_converts_to_csv_error() {
43        let err = io::Error::other("boom");
44        let csv_err: CsvError = err.into();
45        assert!(matches!(csv_err, CsvError::Io(_)));
46    }
47}