use crate::workload_api::error::WorkloadApiError;
use std::fmt;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum JwtSourceError {
#[error("jwt source error: {0}")]
Source(#[from] WorkloadApiError),
#[error("failed to fetch jwt svid: {0}")]
FetchJwtSvid(WorkloadApiError),
#[error("source is closed")]
Closed,
#[error("workload api stream ended")]
StreamEnded,
#[error("resource limit exceeded: {kind} (limit={limit}, actual={actual})")]
ResourceLimitExceeded {
kind: LimitKind,
limit: usize,
actual: usize,
},
#[error("shutdown timeout exceeded")]
ShutdownTimeout,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum LimitKind {
MaxBundles,
MaxBundleJwksBytes,
}
impl LimitKind {
pub const fn as_str(self) -> &'static str {
match self {
Self::MaxBundles => "max_bundles",
Self::MaxBundleJwksBytes => "max_bundle_jwks_bytes",
}
}
}
impl fmt::Display for LimitKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum MetricsErrorKind {
ClientCreation,
StreamConnect,
StreamError,
StreamEnded,
InitialSyncFailed,
LimitMaxBundles,
LimitMaxBundleJwksBytes,
UpdateRejected,
SupervisorJoinFailed,
}
impl MetricsErrorKind {
pub const fn as_str(self) -> &'static str {
match self {
Self::ClientCreation => "client_creation",
Self::StreamConnect => "stream_connect",
Self::StreamError => "stream_error",
Self::StreamEnded => "stream_ended",
Self::InitialSyncFailed => "initial_sync_failed",
Self::LimitMaxBundles => "limit_max_bundles",
Self::LimitMaxBundleJwksBytes => "limit_max_bundle_jwks_bytes",
Self::UpdateRejected => "update_rejected",
Self::SupervisorJoinFailed => "supervisor_join_failed",
}
}
}
impl fmt::Display for MetricsErrorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}