diff options
author | Sven-Hendrik Haase <svenstaro@gmail.com> | 2021-03-20 22:32:25 +0000 |
---|---|---|
committer | Sven-Hendrik Haase <svenstaro@gmail.com> | 2021-03-20 22:32:25 +0000 |
commit | 9edc6b3055f20635b4c903da0451073fd26562ae (patch) | |
tree | 868cf15935050fb1c1cf85d38a1ae72f4c850ca9 /src | |
parent | Merge pull request #471 from svenstaro/show-hidden (diff) | |
download | miniserve-9edc6b3055f20635b4c903da0451073fd26562ae.tar.gz miniserve-9edc6b3055f20635b4c903da0451073fd26562ae.zip |
Switch from failure to thiserror
Diffstat (limited to 'src')
-rw-r--r-- | src/errors.rs | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/src/errors.rs b/src/errors.rs index 1330390..3287fc3 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,76 +1,65 @@ -use failure::Fail; +use thiserror::Error; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum ContextualError { /// Fully customized errors, not inheriting from any error - #[fail(display = "{}", _0)] + #[error("{0}")] CustomError(String), /// Any kind of IO errors - #[fail(display = "{}\ncaused by: {}", _0, _1)] + #[error("{0}\ncaused by: {1}")] IoError(String, std::io::Error), /// MultipartError, which might occur during file upload, when processing the multipart request fails - #[fail(display = "Failed to process multipart request\ncaused by: {}", _0)] + #[error("Failed to process multipart request\ncaused by: {0}")] MultipartError(actix_multipart::MultipartError), /// Any error related to an invalid path (failed to retrieve entry name, unexpected entry type, etc) - #[fail(display = "Invalid path\ncaused by: {}", _0)] + #[error("Invalid path\ncaused by: {0}")] InvalidPathError(String), /// This error might occur if the HTTP credential string does not respect the expected format - #[fail( - display = "Invalid format for credentials string. Expected username:password, username:sha256:hash or username:sha512:hash" - )] + #[error("Invalid format for credentials string. Expected username:password, username:sha256:hash or username:sha512:hash")] InvalidAuthFormat, /// This error might occure if the hash method is neither sha256 nor sha512 - #[fail( - display = "{} is not a valid hashing method. Expected sha256 or sha512", - _0 - )] + #[error("{0} is not a valid hashing method. Expected sha256 or sha512")] InvalidHashMethod(String), /// This error might occur if the HTTP auth hash password is not a valid hex code - #[fail(display = "Invalid format for password hash. Expected hex code")] + #[error("Invalid format for password hash. Expected hex code")] InvalidPasswordHash, /// This error might occur if the HTTP auth password exceeds 255 characters - #[fail(display = "HTTP password length exceeds 255 characters")] + #[error("HTTP password length exceeds 255 characters")] PasswordTooLongError, /// This error might occur if the user has unsufficient permissions to create an entry in a given directory - #[fail(display = "Insufficient permissions to create file in {}", _0)] + #[error("Insufficient permissions to create file in {0}")] InsufficientPermissionsError(String), /// Any error related to parsing. - #[fail(display = "Failed to parse {}\ncaused by: {}", _0, _1)] + #[error("Failed to parse {0}\ncaused by: {1}")] ParseError(String, String), /// This error might occur when the creation of an archive fails - #[fail( - display = "An error occured while creating the {}\ncaused by: {}", - _0, _1 - )] + #[error("An error occured while creating the {0}\ncaused by: {1}")] ArchiveCreationError(String, Box<ContextualError>), /// This error might occur when the HTTP authentication fails - #[fail( - display = "An error occured during HTTP authentication\ncaused by: {}", - _0 - )] + #[error("An error occured during HTTP authentication\ncaused by: {0}")] HttpAuthenticationError(Box<ContextualError>), /// This error might occur when the HTTP credentials are not correct - #[fail(display = "Invalid credentials for HTTP authentication")] + #[error("Invalid credentials for HTTP authentication")] InvalidHttpCredentials, /// This error might occur when an HTTP request is invalid - #[fail(display = "Invalid HTTP request\ncaused by: {}", _0)] + #[error("Invalid HTTP request\ncaused by: {0}")] InvalidHttpRequestError(String), /// This error might occur when trying to access a page that does not exist - #[fail(display = "Route {} could not be found", _0)] + #[error("Route {0} could not be found")] RouteNotFoundError(String), } |