textfile-metrics 0.1.0

Non-blocking Prometheus textfile metrics writer with Counter and Gauge helpers
Documentation
// Copyright (c) Ted Kaplan. All Rights Reserved.
// SPDX-License-Identifier: MIT

//! Error types for metrics operations.

use std::io;

use thiserror::Error;

/// Result type for metrics operations.
pub type Result<T> = std::result::Result<T, MetricsError>;

/// Error types for metrics operations.
#[derive(Error, Debug)]
pub enum MetricsError {
    /// I/O error during metrics write.
    #[error("I/O error: {0}")]
    IoError(#[from] io::Error),

    /// Invalid metric value (e.g., NaN, Inf).
    #[error("Invalid metric value: {0}")]
    InvalidValue(String),

    /// Invalid metric name.
    #[error("Invalid metric name: {0}")]
    InvalidName(String),

    /// Invalid label format.
    #[error("Invalid label: {0}")]
    InvalidLabel(String),

    /// Path configuration error.
    #[error("Path configuration error: {0}")]
    PathError(String),

    /// Serialization error.
    #[error("Serialization error: {0}")]
    SerializationError(String),

    /// Generic error.
    #[error("Operation failed: {0}")]
    Other(String),
}

impl From<String> for MetricsError {
    fn from(err: String) -> Self {
        MetricsError::Other(err)
    }
}

impl From<&str> for MetricsError {
    fn from(err: &str) -> Self {
        MetricsError::Other(err.to_string())
    }
}