footing 0.6.5

Feature-gated foundations for Rust backend services
Documentation
//! Structured event and health-report construction errors.

use std::fmt;

use thiserror::Error;

use crate::result::{ClassifyError, ErrorKind};

#[derive(Error)]
#[non_exhaustive]
/// Errors that can occur while handling observability.
pub enum ObservabilityError {
    #[error("trace field name is invalid")]
    /// The trace field name is invalid.
    InvalidTraceFieldName,
    #[error("event name is invalid")]
    /// The event name is invalid.
    InvalidEventName,
    #[error("health resource name is invalid")]
    /// The health name is invalid.
    InvalidHealthName,
}

impl fmt::Debug for ObservabilityError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("ObservabilityError")
            .field("code", &self.error_code())
            .finish_non_exhaustive()
    }
}

impl ClassifyError for ObservabilityError {
    fn error_kind(&self) -> ErrorKind {
        ErrorKind::Validation
    }

    fn error_code(&self) -> crate::result::ErrorCode {
        crate::result::ErrorCode::internal(match self {
            Self::InvalidTraceFieldName => "trace_field_name_invalid",
            Self::InvalidEventName => "event_name_invalid",
            Self::InvalidHealthName => "health_name_invalid",
        })
    }
}