Skip to main content

synapse_rs/
error.rs

1//! Errors returned when network metrics cannot be computed.
2
3use std::fmt;
4
5/// Errors that can occur while calculating Synapse metrics.
6#[derive(Debug, Clone, PartialEq)]
7pub enum SynapseError {
8    /// One or more required fields were not provided.
9    MissingField(&'static str),
10    /// A numeric field was NaN, infinite, or outside its valid domain.
11    InvalidValue {
12        /// Name of the invalid field.
13        field: &'static str,
14        /// Why the value was rejected.
15        reason: &'static str,
16    },
17}
18
19impl fmt::Display for SynapseError {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            Self::MissingField(field) => write!(f, "missing required field: {field}"),
23            Self::InvalidValue { field, reason } => {
24                write!(f, "invalid value for {field}: {reason}")
25            }
26        }
27    }
28}
29
30impl std::error::Error for SynapseError {}
31
32/// Convenient alias for Synapse calculation results.
33pub type Result<T> = std::result::Result<T, SynapseError>;