use tonic::Status;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Clone, thiserror::Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error("Channel error: {context}")]
ChannelError { context: String },
#[error("ID error: {0:?}")]
IdGeneration(#[from] core::convert::Infallible),
#[error("Request cancelled by client")]
RequestCancelled,
#[error("Invalid request: {reason}")]
InvalidRequest { reason: String },
#[error("Service is shutting down")]
ServiceShutdown,
}
impl From<Error> for Status {
fn from(err: Error) -> Self {
match err {
Error::ChannelError { context } => Self::internal(format!("Channel error: {context}")),
Error::IdGeneration(e) => Self::internal(format!("ID generation error: {e:?}")),
Error::RequestCancelled => Self::cancelled("Request was cancelled"),
Error::InvalidRequest { reason } => Self::invalid_argument(reason),
Error::ServiceShutdown => Self::unavailable("Service is shutting down"),
}
}
}