use crate::BoxError;
use derive_more::Display;
use thiserror::Error;
#[derive(Debug, Error)]
#[error("storage error: {kind}")]
pub struct Error {
kind: ErrorKind,
#[source]
source: Option<BoxError>,
}
impl Error {
pub fn new<E>(kind: ErrorKind, error: E) -> Error
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
Error {
kind,
source: Some(error.into()),
}
}
pub fn kind(&self) -> ErrorKind {
self.kind
}
pub fn get_io_error(&self) -> Option<&std::io::Error> {
self.source.as_ref()?.downcast_ref::<std::io::Error>()
}
}
impl From<ErrorKind> for Error {
fn from(kind: ErrorKind) -> Error {
Error { kind, source: None }
}
}
#[derive(Copy, Clone, Eq, PartialEq, Debug, Display)]
pub enum ErrorKind {
#[display("450 Transient file not available")]
TransientFileNotAvailable,
#[display("550 Permanent file not available")]
PermanentFileNotAvailable,
#[display("550 Permanent directory not available")]
PermanentDirectoryNotAvailable,
#[display("550 The directory is not empty")]
PermanentDirectoryNotEmpty,
#[display("550 Permission denied")]
PermissionDenied,
#[display("426 Connection closed transfer aborted")]
ConnectionClosed,
#[display("451 Local error")]
LocalError,
#[display("551 Page type unknown")]
PageTypeUnknown,
#[display("452 Insufficient storage space error")]
InsufficientStorageSpaceError,
#[display("552 Exceeded storage allocation error")]
ExceededStorageAllocationError,
#[display("553 File name not allowed error")]
FileNameNotAllowedError,
#[display("502 Command not implemented")]
CommandNotImplemented,
}