diff options
author | boasting-squirrel <boasting.squirrel@gmail.com> | 2019-03-19 19:08:57 +0000 |
---|---|---|
committer | boasting-squirrel <boasting.squirrel@gmail.com> | 2019-03-19 19:08:57 +0000 |
commit | 5b5f599055fb6221936c0985f656d0c4b7b2cb23 (patch) | |
tree | 843be589b13ff591d16f75f4e5beb1d3c62f1be2 | |
parent | Removed Content-Length (diff) | |
download | miniserve-5b5f599055fb6221936c0985f656d0c4b7b2cb23.tar.gz miniserve-5b5f599055fb6221936c0985f656d0c4b7b2cb23.zip |
Added documentation for errors and removed useless errors
-rw-r--r-- | src/archive.rs | 11 | ||||
-rw-r--r-- | src/errors.rs | 14 |
2 files changed, 18 insertions, 7 deletions
diff --git a/src/archive.rs b/src/archive.rs index bc8ea3b..fcf39fd 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -82,9 +82,14 @@ fn tgz_compress( let dst_filename = format!("{}.tar", inner_folder); let dst_tgz_filename = format!("{}.gz", dst_filename); - let tar_content = tar(src_dir, inner_folder.to_string(), skip_symlinks) - .context(errors::CompressionErrorKind::TarContentError)?; - let gz_data = gzip(&tar_content).context(errors::CompressionErrorKind::GZipContentError)?; + let tar_content = tar(src_dir, inner_folder.to_string(), skip_symlinks).context( + errors::CompressionErrorKind::TarBuildingError { + message: "an error occured while writing the TAR archive".to_string(), + }, + )?; + let gz_data = gzip(&tar_content).context(errors::CompressionErrorKind::GZipBuildingError { + message: "an error occured while writing the GZIP archive".to_string(), + })?; let mut data = Bytes::new(); data.extend_from_slice(&gz_data); diff --git a/src/errors.rs b/src/errors.rs index a9b6c74..2aa5f58 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -4,18 +4,24 @@ use std::fmt::{self, Debug, Display}; /// Kinds of errors which might happen during the generation of an archive #[derive(Debug, Fail)] pub enum CompressionErrorKind { + /// This error will occur if the directory name could not be retrieved from the path + /// See https://doc.rust-lang.org/std/path/struct.Path.html#method.file_name #[fail(display = "Invalid path: directory name terminates in \"..\"")] InvalidDirectoryName, + /// This error will occur when trying to convert an OSString into a String, if the path + /// contains invalid UTF-8 characters + /// See https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.to_str #[fail(display = "Invalid path: directory name contains invalid UTF-8 characters")] InvalidUTF8DirectoryName, + /// This error might occur while building a TAR archive, or while writing the termination sections + /// See https://docs.rs/tar/0.4.22/tar/struct.Builder.html#method.append_dir_all + /// and https://docs.rs/tar/0.4.22/tar/struct.Builder.html#method.into_inner #[fail(display = "Failed to create the TAR archive: {}", message)] TarBuildingError { message: String }, + /// This error might occur while building a GZIP archive, or while writing the GZIP trailer + /// See https://docs.rs/libflate/0.1.21/libflate/gzip/struct.Encoder.html#method.finish #[fail(display = "Failed to create the GZIP archive: {}", message)] GZipBuildingError { message: String }, - #[fail(display = "Failed to retrieve TAR content")] - TarContentError, - #[fail(display = "Failed to retrieve GZIP content")] - GZipContentError, } /// Prints the full chain of error, up to the root cause. |