2024-09-04 20:03:34 +02:00
|
|
|
//! ### Errors
|
|
|
|
//! Contains the crate's error types.
|
2024-09-01 02:46:03 +02:00
|
|
|
|
2024-09-04 20:03:34 +02:00
|
|
|
/// An error returned by the server as response to a request.
|
|
|
|
///
|
|
|
|
/// This currently wraps an [http code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status),
|
|
|
|
/// returned as procedure status.
|
2024-09-01 02:46:03 +02:00
|
|
|
#[derive(Debug, thiserror::Error)]
|
2024-09-11 17:50:05 +02:00
|
|
|
#[error("server rejected procedure with error code: {0:?}")]
|
2024-09-04 17:20:59 +02:00
|
|
|
pub struct RemoteError(#[from] tonic::Status);
|
2023-09-04 03:08:52 +02:00
|
|
|
|
2024-09-04 20:03:34 +02:00
|
|
|
/// Wraps [std::result::Result] with a [RemoteError].
|
|
|
|
pub type RemoteResult<T> = std::result::Result<T, RemoteError>;
|
2023-08-19 21:44:27 +02:00
|
|
|
|
2024-09-04 20:03:34 +02:00
|
|
|
/// An error that may occur when processing requests that require new connections.
|
2024-08-06 23:00:04 +02:00
|
|
|
#[derive(Debug, thiserror::Error)]
|
2024-09-01 02:46:03 +02:00
|
|
|
pub enum ConnectionError {
|
2024-09-04 20:03:34 +02:00
|
|
|
/// Underlying [`tonic::transport::Error`].
|
2024-09-11 17:50:05 +02:00
|
|
|
#[error("transport error: {0:?}")]
|
2024-09-01 02:46:03 +02:00
|
|
|
Transport(#[from] tonic::transport::Error),
|
2023-07-30 17:48:55 +02:00
|
|
|
|
2024-09-04 20:03:34 +02:00
|
|
|
/// Error from the remote server, see [`RemoteError`].
|
2024-09-11 17:50:05 +02:00
|
|
|
#[error("server rejected connection attempt: {0:?}")]
|
2024-09-04 17:20:59 +02:00
|
|
|
Remote(#[from] RemoteError),
|
2023-07-30 17:48:55 +02:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:20:59 +02:00
|
|
|
impl From<tonic::Status> for ConnectionError {
|
|
|
|
fn from(value: tonic::Status) -> Self {
|
|
|
|
Self::Remote(RemoteError(value))
|
2023-07-30 17:48:55 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-11 15:34:04 +02:00
|
|
|
|
2024-09-04 20:03:34 +02:00
|
|
|
/// Wraps [std::result::Result] with a [ConnectionError].
|
|
|
|
pub type ConnectionResult<T> = std::result::Result<T, ConnectionError>;
|
2023-08-16 18:58:42 +02:00
|
|
|
|
2024-09-04 20:03:34 +02:00
|
|
|
/// An error that may occur when an [`crate::api::Controller`] attempts to
|
|
|
|
/// perform an illegal operation.
|
2024-09-01 02:46:03 +02:00
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
|
|
pub enum ControllerError {
|
2024-09-04 20:03:34 +02:00
|
|
|
/// Error occurred because the underlying controller worker is already stopped.
|
2024-09-01 02:46:03 +02:00
|
|
|
#[error("worker is already stopped")]
|
|
|
|
Stopped,
|
|
|
|
|
2024-09-04 20:03:34 +02:00
|
|
|
/// Error occurred because the underlying controller worker stopped before
|
|
|
|
/// fulfilling the request, without rejecting it first.
|
2024-09-01 02:46:03 +02:00
|
|
|
#[error("worker stopped before completing requested operation")]
|
|
|
|
Unfulfilled,
|
2023-08-16 18:58:42 +02:00
|
|
|
}
|
2023-08-21 02:35:56 +02:00
|
|
|
|
2024-09-01 02:46:03 +02:00
|
|
|
impl<T> From<tokio::sync::mpsc::error::SendError<T>> for ControllerError {
|
|
|
|
fn from(_: tokio::sync::mpsc::error::SendError<T>) -> Self {
|
|
|
|
Self::Stopped
|
2024-08-13 18:00:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-01 02:46:03 +02:00
|
|
|
impl From<tokio::sync::oneshot::error::RecvError> for ControllerError {
|
|
|
|
fn from(_: tokio::sync::oneshot::error::RecvError) -> Self {
|
|
|
|
Self::Unfulfilled
|
2023-08-21 02:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
2024-09-04 20:03:34 +02:00
|
|
|
|
|
|
|
/// Wraps [std::result::Result] with a [ControllerError].
|
|
|
|
pub type ControllerResult<T> = std::result::Result<T, ControllerError>;
|
|
|
|
|