use std::sync::Arc;
use std::time::Duration;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, ServiceError>;
#[derive(Error, Debug, Clone)]
pub enum ServiceError {
#[error("pre_start failed: {0}")]
PreStartFailed(#[source] Arc<anyhow::Error>),
#[error("on_start failed: {0}")]
OnStartFailed(#[source] Arc<anyhow::Error>),
#[error("run exited with error: {0}")]
RunFailed(#[source] Arc<anyhow::Error>),
#[error("on_stop failed: {0}")]
OnStopFailed(#[source] Arc<anyhow::Error>),
#[error("task registry deadline exceeded ({deadline:?}); {pending} tasks aborted")]
ShutdownDeadlineExceeded {
deadline: Duration,
pending: usize,
},
#[error("service is already running")]
AlreadyRunning,
#[error("service has already stopped")]
AlreadyStopped,
}