Skip to content

Commit

Permalink
change error names
Browse files Browse the repository at this point in the history
  • Loading branch information
tamada committed Jun 18, 2024
1 parent 38ba85d commit b5a1f18
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 36 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "albatros"]
path = site/themes/albatros
url = https://git.42l.fr/HugoTrentesaux/albatros.git
1 change: 0 additions & 1 deletion site/themes/albatros
Submodule albatros deleted from 139388
4 changes: 2 additions & 2 deletions src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ impl ArchiverOpts {
if let Some(parent) = p.parent() {
if !parent.exists() {
if let Err(e) = create_dir_all(parent) {
return Err(ToteError::IOError(e));
return Err(ToteError::IO(e));
}
}
}
match File::create(self.dest.as_path()) {
Ok(f) => Ok(f),
Err(e) => Err(ToteError::IOError(e)),
Err(e) => Err(ToteError::IO(e)),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/archiver/sevenz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn process_file(szw: &mut SevenZWriter<File>, target: PathBuf) -> Result<()> {
SevenZArchiveEntry::from_path(&target, name.to_string()),
Some(File::open(target).unwrap()),
) {
return Err(ToteError::ArchiverError(e.to_string()));
return Err(ToteError::Archiver(e.to_string()));
}
Ok(())
}
Expand Down Expand Up @@ -61,15 +61,15 @@ fn write_sevenz_impl(
}
}
if let Err(e) = szw.finish() {
return Err(ToteError::ArchiverError(e.to_string()));
return Err(ToteError::Archiver(e.to_string()));
}
Ok(())
}

fn write_sevenz(dest: File, targets: Vec<PathBuf>, recursive: bool) -> Result<()> {
match SevenZWriter::new(dest) {
Ok(write) => write_sevenz_impl(write, targets, recursive),
Err(e) => Err(ToteError::ArchiverError(e.to_string())),
Err(e) => Err(ToteError::Archiver(e.to_string())),
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/archiver/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ fn write_tar_impl<W: Write>(file: W, targets: Vec<PathBuf>, recursive: bool) ->
}
}
if let Err(e) = builder.finish() {
return Err(ToteError::ArchiverError(e.to_string()))
return Err(ToteError::Archiver(e.to_string()))
}
Ok(())
}

fn process_dir<W: Write>(builder: &mut Builder<W>, target: PathBuf, recursive: bool) -> Result<()> {
if let Err(e) = builder.append_dir(&target, &target) {
return Err(ToteError::ArchiverError(e.to_string()))
return Err(ToteError::Archiver(e.to_string()))
}
for entry in target.read_dir().unwrap() {
if let Ok(e) = entry {
Expand All @@ -114,7 +114,7 @@ fn process_dir<W: Write>(builder: &mut Builder<W>, target: PathBuf, recursive: b

fn process_file<W: Write>(builder: &mut Builder<W>, target: PathBuf) -> Result<()> {
if let Err(e) = builder.append_path(target) {
Err(ToteError::ArchiverError(e.to_string()))
Err(ToteError::Archiver(e.to_string()))
} else {
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions src/archiver/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ fn process_file<W:Write+Seek> (zw: &mut ZipWriter<W>, target: PathBuf) -> Result
let name = target.to_str().unwrap();
let opts = create(&target);
if let Err(e) = zw.start_file(name, opts) {
return Err(ToteError::ArchiverError(e.to_string()));
return Err(ToteError::Archiver(e.to_string()));
}
let mut file = BufReader::new(File::open(target).unwrap());
if let Err(e) = std::io::copy(&mut file, zw) {
return Err(ToteError::IOError(e))
return Err(ToteError::IO(e))
}
Ok(())
}
Expand All @@ -69,7 +69,7 @@ fn write_to_zip(dest: File, targets: Vec<PathBuf>, recursive: bool) -> Result<()
}
}
if let Err(e) = zw.finish() {
return Err(ToteError::ArchiverError(e.to_string()));
return Err(ToteError::Archiver(e.to_string()));
}
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ pub enum ToteError {
NoArgumentsGiven,
FileNotFound(PathBuf),
FileExists(PathBuf),
IOError(std::io::Error),
ArchiverError(String),
IO(std::io::Error),
Archiver(String),
UnsupportedFormat(String),
UnknownFormat(String),
UnknownError(String),
SomeError(Box<dyn std::error::Error>)
Unknown(String),
Fatal(Box<dyn std::error::Error>)
}

#[cfg(test)]
Expand Down
14 changes: 7 additions & 7 deletions src/extractor/lha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Extractor for LhaExtractor {
fn list_archives(&self, archive_file: PathBuf) -> Result<Vec<String>> {
let mut result = Vec::<String>::new();
let mut reader = match delharc::parse_file(&archive_file) {
Err(e) => return Err(ToteError::IOError(e)),
Err(e) => return Err(ToteError::IO(e)),
Ok(h) => h,
};
loop {
Expand All @@ -26,15 +26,15 @@ impl Extractor for LhaExtractor {
break;
}
}
Err(e) => return Err(ToteError::SomeError(Box::new(e))),
Err(e) => return Err(ToteError::Fatal(Box::new(e))),
}
}
Ok(result)
}

fn perform(&self, archive_file: PathBuf, opts: &ExtractorOpts) -> Result<()> {
let mut reader = match delharc::parse_file(&archive_file) {
Err(e) => return Err(ToteError::IOError(e)),
Err(e) => return Err(ToteError::IO(e)),
Ok(h) => h,
};
loop {
Expand All @@ -50,14 +50,14 @@ impl Extractor for LhaExtractor {
create_dir_all(dest.parent().unwrap()).unwrap();
let mut dest = match File::create(dest) {
Ok(f) => f,
Err(e) => return Err(ToteError::IOError(e)),
Err(e) => return Err(ToteError::IO(e)),
};
match copy(&mut reader, &mut dest) {
Ok(_) => {}
Err(e) => return Err(ToteError::IOError(e)),
Err(e) => return Err(ToteError::IO(e)),
}
if let Err(e) = reader.crc_check() {
return Err(ToteError::SomeError(Box::new(e)));
return Err(ToteError::Fatal(Box::new(e)));
};
} else if !header.is_directory() {
opts.v.verbose(format!(
Expand All @@ -71,7 +71,7 @@ impl Extractor for LhaExtractor {
break;
}
}
Err(e) => return Err(ToteError::SomeError(Box::new(e))),
Err(e) => return Err(ToteError::Fatal(Box::new(e))),
}
}
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/extractor/sevenz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ impl Extractor for SevenZExtractor {
}
Ok(r)
},
Err(e) => Err(ToteError::SomeError(Box::new(e))),
Err(e) => Err(ToteError::Fatal(Box::new(e))),
}
}
fn perform(&self, archive_file: PathBuf, opts: &ExtractorOpts) -> Result<()> {
let mut file = match File::open(&archive_file) {
Ok(file) => {
file
},
Err(e) => return Err(ToteError::IOError(e)),
Err(e) => return Err(ToteError::IO(e)),
};
extract(&mut file, archive_file, opts)
}
Expand All @@ -48,7 +48,7 @@ fn extract(mut file: &File, path: PathBuf, opts: &ExtractorOpts) -> Result<()> {
Ok(reader) => {
reader
},
Err(e) => return Err(ToteError::SomeError(Box::new(e))),
Err(e) => return Err(ToteError::Fatal(Box::new(e))),
};
let folder_count = archive.folders.len();
for findex in 0..folder_count {
Expand All @@ -57,7 +57,7 @@ fn extract(mut file: &File, path: PathBuf, opts: &ExtractorOpts) -> Result<()> {
let dest = opts.destination(&path).join(entry.name.clone());
sevenz_rust::default_entry_extract_fn(entry, reader, &dest)
}) {
return Err(ToteError::SomeError(Box::new(e)))
return Err(ToteError::Fatal(Box::new(e)))
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/extractor/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where
{
let file = match File::open(file) {
Ok(f) => f,
Err(e) => return Err(ToteError::IOError(e)),
Err(e) => return Err(ToteError::IO(e)),
};
let writer = opener(file);
Ok(Archive::new(writer))
Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn perform(mut opts: CliOpts) -> Result<()> {
Ok(RunMode::Extract) => return perform_extract(opts),
Ok(RunMode::List) => return perform_list(opts),
Ok(RunMode::Auto) => {
return Err(ToteError::UnknownError(
return Err(ToteError::Unknown(
"cannot distinguish archiving and extracting".to_string(),
))
}
Expand Down Expand Up @@ -81,12 +81,12 @@ fn main() -> Result<()> {
ToteError::FileExists(p) => {
println!("{}: file already exists", p.to_str().unwrap())
}
ToteError::IOError(e) => println!("IO error: {}", e),
ToteError::ArchiverError(s) => println!("Archive error: {}", s),
ToteError::IO(e) => println!("IO error: {}", e),
ToteError::Archiver(s) => println!("Archive error: {}", s),
ToteError::UnknownFormat(f) => println!("{}: unknown format", f),
ToteError::UnsupportedFormat(f) => println!("{}: unsupported format", f),
ToteError::SomeError(e) => println!("Error: {}", e),
ToteError::UnknownError(s) => println!("Unknown error: {}", s),
ToteError::Fatal(e) => println!("Error: {}", e),
ToteError::Unknown(s) => println!("Unknown error: {}", s),
}
std::process::exit(1);
}
Expand Down

0 comments on commit b5a1f18

Please sign in to comment.