use thiserror::Error;
use crate::result::{ClassifyError, ErrorKind};
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum ResourceRegistryError {
#[error(
"resource diagnostic service name must be non-empty and contain only ASCII letters, digits, '-', '_', '.', or ':'"
)]
InvalidServiceName,
#[error("resource diagnostic service name must be less than or equal to {max} bytes")]
ServiceNameTooLong {
#[doc = "The configured upper bound."]
max: usize,
},
#[error(
"resource diagnostic probe timeout must be greater than zero and fit the runtime timer range"
)]
InvalidProbeTimeout,
#[error("resource diagnostics report must contain at most {max} resources")]
TooManyResources {
#[doc = "The configured upper bound."]
max: usize,
},
#[error("duplicate resource diagnostic id {id} at indexes {first_index} and {second_index}")]
DuplicateResourceId {
id: String,
first_index: usize,
second_index: usize,
},
}
impl ClassifyError for ResourceRegistryError {
fn error_kind(&self) -> ErrorKind {
ErrorKind::Validation
}
fn error_code(&self) -> crate::result::ErrorCode {
crate::result::ErrorCode::internal(match self {
Self::InvalidServiceName => "resource_diagnostics_invalid_service_name",
Self::ServiceNameTooLong { .. } => "resource_diagnostics_service_name_too_long",
Self::InvalidProbeTimeout => "resource_diagnostics_invalid_probe_timeout",
Self::TooManyResources { .. } => "resource_diagnostics_too_many_resources",
Self::DuplicateResourceId { .. } => "resource_diagnostics_duplicate_resource_id",
})
}
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum ResourceDescriptorError {
#[error("resource diagnostic id must not be empty")]
EmptyId,
#[error("resource diagnostic id must be less than or equal to {max} bytes")]
IdTooLong {
#[doc = "The configured upper bound."]
max: usize,
},
#[error(
"resource diagnostic id must contain only ASCII letters, digits, '-', '_', '.', or ':'"
)]
InvalidId,
#[error("resource diagnostic name must not be empty")]
EmptyName,
#[error("resource diagnostic name must be less than or equal to {max} bytes")]
NameTooLong {
#[doc = "The configured upper bound."]
max: usize,
},
#[error("resource diagnostic name must not contain control characters")]
InvalidName,
#[error("resource diagnostic label key must not be empty")]
EmptyLabelKey,
#[error("resource diagnostic label key must be less than or equal to {max} bytes")]
LabelKeyTooLong {
#[doc = "The configured upper bound."]
max: usize,
},
#[error(
"resource diagnostic label key must contain only ASCII letters, digits, '-', '_', '.', or ':'"
)]
InvalidLabelKey,
#[error("resource diagnostic label {key} value must not be empty")]
EmptyLabelValue {
#[doc = "The associated key."]
key: String,
},
#[error("resource diagnostic label {key} value must be less than or equal to {max} bytes")]
LabelValueTooLong {
#[doc = "The associated key."]
key: String,
#[doc = "The configured upper bound."]
max: usize,
},
#[error("resource diagnostic label {key} value must not contain control characters")]
InvalidLabelValue {
#[doc = "The associated key."]
key: String,
},
#[error("resource descriptor must contain at most {max} labels")]
TooManyLabels {
#[doc = "The configured upper bound."]
max: usize,
},
}
impl ClassifyError for ResourceDescriptorError {
fn error_kind(&self) -> ErrorKind {
ErrorKind::Validation
}
fn error_code(&self) -> crate::result::ErrorCode {
crate::result::ErrorCode::internal(match self {
Self::EmptyId => "resource_descriptor_empty_id",
Self::IdTooLong { .. } => "resource_descriptor_id_too_long",
Self::InvalidId => "resource_descriptor_invalid_id",
Self::EmptyName => "resource_descriptor_empty_name",
Self::NameTooLong { .. } => "resource_descriptor_name_too_long",
Self::InvalidName => "resource_descriptor_invalid_name",
Self::EmptyLabelKey => "resource_descriptor_empty_label_key",
Self::LabelKeyTooLong { .. } => "resource_descriptor_label_key_too_long",
Self::InvalidLabelKey => "resource_descriptor_invalid_label_key",
Self::EmptyLabelValue { .. } => "resource_descriptor_empty_label_value",
Self::LabelValueTooLong { .. } => "resource_descriptor_label_value_too_long",
Self::InvalidLabelValue { .. } => "resource_descriptor_invalid_label_value",
Self::TooManyLabels { .. } => "resource_descriptor_too_many_labels",
})
}
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum ResourceDiagnosticError {
#[error("resource diagnostic must contain at most {max} details")]
TooManyDetails {
#[doc = "The configured upper bound."]
max: usize,
},
#[error("resource diagnostic must contain at most {max} remediations")]
TooManyRemediations {
#[doc = "The configured upper bound."]
max: usize,
},
}
impl ClassifyError for ResourceDiagnosticError {
fn error_kind(&self) -> ErrorKind {
ErrorKind::Validation
}
fn error_code(&self) -> crate::result::ErrorCode {
crate::result::ErrorCode::internal(match self {
Self::TooManyDetails { .. } => "resource_diagnostic_too_many_details",
Self::TooManyRemediations { .. } => "resource_diagnostic_too_many_remediations",
})
}
}