use std::result;
use std::sync::PoisonError;
use thiserror::Error;
use crate::export::ExportError;
pub type MetricResult<T> = result::Result<T, MetricError>;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum MetricError {
#[error("Metrics error: {0}")]
Other(String),
#[error("Config error {0}")]
Config(String),
#[error("Metrics exporter {} failed with {0}", .0.exporter_name())]
ExportErr(Box<dyn ExportError>),
#[error("Invalid instrument configuration: {0}")]
InvalidInstrumentConfiguration(&'static str),
}
impl<T: ExportError> From<T> for MetricError {
fn from(err: T) -> Self {
MetricError::ExportErr(Box::new(err))
}
}
impl<T> From<PoisonError<T>> for MetricError {
fn from(err: PoisonError<T>) -> Self {
MetricError::Other(err.to_string())
}
}