Skip to main content

textfile_metrics/
errors.rs

1// Copyright (c) Ted Kaplan. All Rights Reserved.
2// SPDX-License-Identifier: MIT
3
4//! Error types for metrics operations.
5
6use std::io;
7
8use thiserror::Error;
9
10/// Result type for metrics operations.
11pub type Result<T> = std::result::Result<T, MetricsError>;
12
13/// Error types for metrics operations.
14#[derive(Error, Debug)]
15pub enum MetricsError {
16    /// I/O error during metrics write.
17    #[error("I/O error: {0}")]
18    IoError(#[from] io::Error),
19
20    /// Invalid metric value (e.g., NaN, Inf).
21    #[error("Invalid metric value: {0}")]
22    InvalidValue(String),
23
24    /// Invalid metric name.
25    #[error("Invalid metric name: {0}")]
26    InvalidName(String),
27
28    /// Invalid label format.
29    #[error("Invalid label: {0}")]
30    InvalidLabel(String),
31
32    /// Path configuration error.
33    #[error("Path configuration error: {0}")]
34    PathError(String),
35
36    /// Serialization error.
37    #[error("Serialization error: {0}")]
38    SerializationError(String),
39
40    /// Generic error.
41    #[error("Operation failed: {0}")]
42    Other(String),
43}
44
45impl From<String> for MetricsError {
46    fn from(err: String) -> Self {
47        MetricsError::Other(err)
48    }
49}
50
51impl From<&str> for MetricsError {
52    fn from(err: &str) -> Self {
53        MetricsError::Other(err.to_string())
54    }
55}