1use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue, LabelValueEncoder};
2use serde::{Deserialize, Serialize};
3use std::fmt::Error as FmtError;
4use std::fmt::Write;
5use thiserror::Error;
6
7#[derive(PartialEq, Eq, Clone, Hash, Error, Debug, Serialize, Deserialize)]
8pub enum InclusionServiceError {
9 #[error("Blob index not found")]
10 MissingBlobIndex,
11
12 #[error("Inclusion proof sanity check failed")]
13 FailedShareRangeProofSanityCheck,
14
15 #[error("Failed to convert keccak hash to array")]
16 KeccakHashConversion,
17
18 #[error("Failed to verify row root inclusion multiproof")]
19 RowRootVerificationFailed,
20
21 #[error("Failed to convert shares to blob: {0}")]
22 ShareConversionError(String),
23
24 #[error("Failed with: {0}")]
25 InternalError(String),
26
27 #[error("{0}")]
28 ZkClientError(String),
29
30 #[error("{0}")]
31 DaClientError(String),
32
33 #[error("Invalid parameter: {0}")]
34 InvalidParameter(String),
35
36 #[error("Failed to deserialize KeccakInclusionToDataRootProofOutput")]
37 OutputDeserializationError,
38}
39
40impl EncodeLabelValue for InclusionServiceError {
41 fn encode(&self, encoder: &mut LabelValueEncoder) -> Result<(), FmtError> {
42 use InclusionServiceError::*;
43 let name: String = match self {
44 MissingBlobIndex => "MissingBlobIndex".to_string(),
45 FailedShareRangeProofSanityCheck => "FailedShareRangeProofSanityCheck".to_string(),
46 KeccakHashConversion => "KeccakHashConversion".to_string(),
47 RowRootVerificationFailed => "RowRootVerificationFailed".to_string(),
48 ShareConversionError(e) => format!("ShareConversionError({})", e),
49 InternalError(e) => format!("ShareConversionError({})", e),
50 ZkClientError(e) => format!("ZkClientError({})", e),
51 DaClientError(e) => format!("DaClientError({})", e),
52 InvalidParameter(e) => format!("InvalidParameter({})", e),
53 OutputDeserializationError => "OutputDeserializationError".to_string(),
54 };
55 encoder.write_str(name.as_str())?;
56 Ok(())
57 }
58}
59
60#[derive(Debug, Clone, Hash, PartialEq, Eq, EncodeLabelSet)]
61pub struct ErrorLabels {
62 pub error_type: InclusionServiceError,
63}