use std::error::Error;
use std::fmt;
use std::io;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AttemptExecutorError {
message: Box<str>,
}
impl AttemptExecutorError {
#[inline]
pub fn new(message: &str) -> Self {
Self {
message: message.into(),
}
}
#[inline]
#[cfg_attr(coverage, allow(dead_code))]
pub(crate) fn from_spawn_error(error: io::Error) -> Self {
Self::new(&format!("failed to spawn retry worker thread: {error}"))
}
#[inline]
pub(crate) fn from_worker_disconnected() -> Self {
Self::new("retry worker thread stopped without sending a result")
}
#[inline]
pub fn message(&self) -> &str {
&self.message
}
}
impl fmt::Display for AttemptExecutorError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.message)
}
}
impl Error for AttemptExecutorError {}