opentelemetry_sdk/metrics/
error.rs

1use std::result;
2use std::sync::PoisonError;
3use thiserror::Error;
4
5/// A specialized `Result` type for metric operations.
6pub(crate) type MetricResult<T> = result::Result<T, MetricError>;
7
8/// Errors returned by the metrics API.
9#[derive(Error, Debug)]
10pub(crate) enum MetricError {
11    /// Other errors not covered by specific cases.
12    #[error("Metrics error: {0}")]
13    Other(String),
14    /// Invalid configuration
15    #[error("Config error {0}")]
16    Config(String),
17    /// Invalid instrument configuration such invalid instrument name, invalid instrument description, invalid instrument unit, etc.
18    /// See [spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#general-characteristics)
19    /// for full list of requirements.
20    #[error("Invalid instrument configuration: {0}")]
21    InvalidInstrumentConfiguration(&'static str),
22}
23
24impl<T> From<PoisonError<T>> for MetricError {
25    fn from(err: PoisonError<T>) -> Self {
26        MetricError::Other(err.to_string())
27    }
28}