2021-03-20 19:38:44 +00:00
|
|
|
//! Module containing error types used in Garage
|
2020-04-09 15:32:28 +00:00
|
|
|
use err_derive::Error;
|
|
|
|
use hyper::StatusCode;
|
2020-04-10 20:01:48 +00:00
|
|
|
use std::io;
|
2020-04-05 21:33:42 +00:00
|
|
|
|
2020-04-24 10:10:01 +00:00
|
|
|
use crate::data::*;
|
|
|
|
|
2021-03-20 19:38:44 +00:00
|
|
|
/// RPC related errors
|
2020-04-24 10:10:01 +00:00
|
|
|
#[derive(Debug, Error)]
|
2021-05-02 21:13:08 +00:00
|
|
|
pub enum RpcError {
|
2020-04-24 10:10:01 +00:00
|
|
|
#[error(display = "Node is down: {:?}.", _0)]
|
2021-05-02 21:13:08 +00:00
|
|
|
NodeDown(Uuid),
|
2021-03-15 21:36:41 +00:00
|
|
|
|
2021-10-14 09:50:12 +00:00
|
|
|
#[error(display = "Timeout")]
|
|
|
|
Timeout,
|
2021-03-15 21:36:41 +00:00
|
|
|
|
2020-04-24 10:10:01 +00:00
|
|
|
#[error(display = "HTTP error: {}", _0)]
|
2021-05-02 21:13:08 +00:00
|
|
|
Http(#[error(source)] http::Error),
|
2021-03-15 21:36:41 +00:00
|
|
|
|
2020-04-24 10:10:01 +00:00
|
|
|
#[error(display = "Hyper error: {}", _0)]
|
|
|
|
Hyper(#[error(source)] hyper::Error),
|
2021-03-15 21:36:41 +00:00
|
|
|
|
2020-04-24 10:10:01 +00:00
|
|
|
#[error(display = "Messagepack encode error: {}", _0)]
|
2021-05-02 21:13:08 +00:00
|
|
|
RmpEncode(#[error(source)] rmp_serde::encode::Error),
|
2021-03-15 21:36:41 +00:00
|
|
|
|
2020-04-24 10:10:01 +00:00
|
|
|
#[error(display = "Messagepack decode error: {}", _0)]
|
2021-05-02 21:13:08 +00:00
|
|
|
RmpDecode(#[error(source)] rmp_serde::decode::Error),
|
2021-03-15 21:36:41 +00:00
|
|
|
|
2020-04-24 10:10:01 +00:00
|
|
|
#[error(display = "Too many errors: {:?}", _0)]
|
|
|
|
TooManyErrors(Vec<String>),
|
|
|
|
}
|
2020-04-17 13:36:16 +00:00
|
|
|
|
2021-03-20 19:38:44 +00:00
|
|
|
/// Regroup all Garage errors
|
2020-04-05 21:33:42 +00:00
|
|
|
#[derive(Debug, Error)]
|
|
|
|
pub enum Error {
|
2020-04-07 16:10:20 +00:00
|
|
|
#[error(display = "IO error: {}", _0)]
|
2020-04-05 21:33:42 +00:00
|
|
|
Io(#[error(source)] io::Error),
|
|
|
|
|
2020-04-07 16:10:20 +00:00
|
|
|
#[error(display = "Hyper error: {}", _0)]
|
2020-04-05 21:33:42 +00:00
|
|
|
Hyper(#[error(source)] hyper::Error),
|
|
|
|
|
2020-04-07 16:10:20 +00:00
|
|
|
#[error(display = "HTTP error: {}", _0)]
|
2021-05-02 21:13:08 +00:00
|
|
|
Http(#[error(source)] http::Error),
|
2020-04-06 17:55:39 +00:00
|
|
|
|
2020-04-10 20:01:48 +00:00
|
|
|
#[error(display = "Invalid HTTP header value: {}", _0)]
|
2021-05-02 21:13:08 +00:00
|
|
|
HttpHeader(#[error(source)] http::header::ToStrError),
|
2020-04-07 22:39:07 +00:00
|
|
|
|
2021-10-14 09:50:12 +00:00
|
|
|
#[error(display = "Netapp error: {}", _0)]
|
|
|
|
Netapp(#[error(source)] netapp::error::Error),
|
2020-04-12 13:51:19 +00:00
|
|
|
|
2020-04-08 21:01:49 +00:00
|
|
|
#[error(display = "Sled error: {}", _0)]
|
|
|
|
Sled(#[error(source)] sled::Error),
|
|
|
|
|
2020-04-07 16:10:20 +00:00
|
|
|
#[error(display = "Messagepack encode error: {}", _0)]
|
2021-05-02 21:13:08 +00:00
|
|
|
RmpEncode(#[error(source)] rmp_serde::encode::Error),
|
2020-04-07 16:10:20 +00:00
|
|
|
#[error(display = "Messagepack decode error: {}", _0)]
|
2021-05-02 21:13:08 +00:00
|
|
|
RmpDecode(#[error(source)] rmp_serde::decode::Error),
|
2020-04-09 16:43:53 +00:00
|
|
|
#[error(display = "JSON error: {}", _0)]
|
2021-05-02 21:13:08 +00:00
|
|
|
Json(#[error(source)] serde_json::error::Error),
|
2020-04-07 16:10:20 +00:00
|
|
|
#[error(display = "TOML decode error: {}", _0)]
|
2020-04-06 17:55:39 +00:00
|
|
|
TomlDecode(#[error(source)] toml::de::Error),
|
|
|
|
|
2020-04-12 10:10:33 +00:00
|
|
|
#[error(display = "Tokio join error: {}", _0)]
|
|
|
|
TokioJoin(#[error(source)] tokio::task::JoinError),
|
|
|
|
|
2020-04-23 16:05:43 +00:00
|
|
|
#[error(display = "RPC call error: {}", _0)]
|
2021-05-02 21:13:08 +00:00
|
|
|
Rpc(#[error(source)] RpcError),
|
2020-04-23 16:05:43 +00:00
|
|
|
|
|
|
|
#[error(display = "Remote error: {} (status code {})", _0, _1)]
|
|
|
|
RemoteError(String, StatusCode),
|
2020-04-06 17:55:39 +00:00
|
|
|
|
2020-11-08 14:04:30 +00:00
|
|
|
#[error(display = "Bad RPC: {}", _0)]
|
2021-05-02 21:13:08 +00:00
|
|
|
BadRpc(String),
|
2020-04-09 15:32:28 +00:00
|
|
|
|
2020-04-17 13:36:16 +00:00
|
|
|
#[error(display = "Corrupt data: does not match hash {:?}", _0)]
|
|
|
|
CorruptData(Hash),
|
|
|
|
|
2020-04-07 16:10:20 +00:00
|
|
|
#[error(display = "{}", _0)]
|
2020-04-06 17:55:39 +00:00
|
|
|
Message(String),
|
2020-04-05 21:33:42 +00:00
|
|
|
}
|
2020-04-09 15:32:28 +00:00
|
|
|
|
2021-02-23 20:27:28 +00:00
|
|
|
impl From<sled::transaction::TransactionError<Error>> for Error {
|
|
|
|
fn from(e: sled::transaction::TransactionError<Error>) -> Error {
|
2020-04-09 18:58:39 +00:00
|
|
|
match e {
|
2021-02-23 20:27:28 +00:00
|
|
|
sled::transaction::TransactionError::Abort(x) => x,
|
|
|
|
sled::transaction::TransactionError::Storage(x) => Error::Sled(x),
|
2020-04-09 18:58:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-11 16:51:11 +00:00
|
|
|
|
|
|
|
impl<T> From<tokio::sync::watch::error::SendError<T>> for Error {
|
|
|
|
fn from(_e: tokio::sync::watch::error::SendError<T>) -> Error {
|
2021-04-09 00:32:42 +00:00
|
|
|
Error::Message("Watch send error".to_string())
|
2020-04-11 16:51:11 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-19 17:59:59 +00:00
|
|
|
|
|
|
|
impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error {
|
|
|
|
fn from(_e: tokio::sync::mpsc::error::SendError<T>) -> Error {
|
2021-04-09 00:32:42 +00:00
|
|
|
Error::Message("MPSC send error".to_string())
|
2020-04-19 17:59:59 +00:00
|
|
|
}
|
|
|
|
}
|