#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum EmbedError {
NoProviders,
NoRuntime,
Blueprint(String),
Spawn(String),
ChannelClosed,
}
impl std::fmt::Display for EmbedError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EmbedError::NoProviders => {
write!(f, "no providers configured: add credentials or a provider")
}
EmbedError::NoRuntime => {
write!(f, "no tokio runtime: build inside one or pass a handle")
}
EmbedError::Blueprint(msg) => write!(f, "blueprint error: {msg}"),
EmbedError::Spawn(msg) => write!(f, "spawn error: {msg}"),
EmbedError::ChannelClosed => write!(f, "the world has shut down"),
}
}
}
impl std::error::Error for EmbedError {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display_covers_every_variant() {
let cases = [
(EmbedError::NoProviders, "no providers"),
(EmbedError::NoRuntime, "no tokio runtime"),
(
EmbedError::Blueprint("bad".to_string()),
"blueprint error: bad",
),
(EmbedError::Spawn("nope".to_string()), "spawn error: nope"),
(EmbedError::ChannelClosed, "shut down"),
];
for (err, needle) in cases {
assert!(err.to_string().contains(needle));
}
}
}