1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.

use thiserror::Error;

/// The error types for prometheus.
#[derive(Debug, Error)]
pub enum Error {
    /// A duplicate metric collector has already been registered.
    #[error("Duplicate metrics collector registration attempted")]
    AlreadyReg,
    /// The label cardinality was inconsistent.
    #[error("Inconsistent label cardinality, expect {expect} label values, but got {got}")]
    InconsistentCardinality {
        /// The expected number of labels.
        expect: usize,
        /// The actual number of labels.
        got: usize,
    },
    /// An error message which is only a string.
    #[error("Error: {0}")]
    Msg(String),
    /// An error containing a [`std::io::Error`].
    #[error("Io error: {0}")]
    Io(#[from] std::io::Error),
    /// An error containing a [`protobuf::error::ProtobufError`].
    #[cfg(feature = "protobuf")]
    #[error("Protobuf error: {0}")]
    Protobuf(#[from] protobuf::error::ProtobufError),
}

/// A specialized Result type for prometheus.
pub type Result<T> = std::result::Result<T, Error>;