use crate::bus::AllocFailReason;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum DeliveryError {
IngressClosed,
UnknownModule(String),
UnknownInput {
module: String,
input: String,
},
InvalidEnvelope(String),
OversizePayload {
byte_count: usize,
cap: usize,
},
TooManyInputs {
count: usize,
cap: usize,
},
AllocationFailed {
byte_count: usize,
reason: AllocFailReason,
},
BudgetExceeded {
byte_count: usize,
budget_remaining: usize,
},
}
impl std::fmt::Display for DeliveryError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::IngressClosed => write!(f, "ingress queue closed"),
Self::UnknownModule(name) => write!(f, "unknown module: {name}"),
Self::UnknownInput { module, input } => {
write!(f, "module {module} has no input port '{input}'")
}
Self::InvalidEnvelope(detail) => {
write!(f, "inbound envelope rejected: {detail}")
}
Self::OversizePayload { byte_count, cap } => {
write!(f, "payload of {byte_count} bytes exceeds cap of {cap}")
}
Self::TooManyInputs { count, cap } => {
write!(f, "{count} inputs exceeds cap of {cap}")
}
Self::AllocationFailed { byte_count, reason } => match reason {
AllocFailReason::HeapExhausted => {
write!(f, "heap exhausted reserving {byte_count} bytes")
}
AllocFailReason::PerItemCapExceeded { cap } => {
write!(
f,
"per-item cap {cap} rejected payload of {byte_count} bytes"
)
}
},
Self::BudgetExceeded {
byte_count,
budget_remaining,
} => write!(
f,
"ingress budget exceeded: {byte_count} bytes requested, {budget_remaining} remaining"
),
}
}
}
impl std::error::Error for DeliveryError {}