prometheus/
errors.rs

1// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
2
3use thiserror::Error;
4
5/// The error types for prometheus.
6#[derive(Debug, Error)]
7pub enum Error {
8    /// A duplicate metric collector has already been registered.
9    #[error("Duplicate metrics collector registration attempted")]
10    AlreadyReg,
11    /// The label cardinality was inconsistent.
12    #[error("Inconsistent label cardinality, expect {expect} label values, but got {got}")]
13    InconsistentCardinality {
14        /// The expected number of labels.
15        expect: usize,
16        /// The actual number of labels.
17        got: usize,
18    },
19    /// An error message which is only a string.
20    #[error("Error: {0}")]
21    Msg(String),
22    /// An error containing a [`std::io::Error`].
23    #[error("Io error: {0}")]
24    Io(#[from] std::io::Error),
25    /// An error containing a [`protobuf::error::ProtobufError`].
26    #[cfg(feature = "protobuf")]
27    #[error("Protobuf error: {0}")]
28    Protobuf(#[from] protobuf::error::ProtobufError),
29}
30
31/// A specialized Result type for prometheus.
32pub type Result<T> = std::result::Result<T, Error>;