Skip to content

Commit eaee855

Browse files
committed
Refactor errors and remove unwraps
1 parent 4177d72 commit eaee855

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

git-worktree/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use quick_error::quick_error;
77
use std::convert::TryFrom;
88
use std::fs;
99
use std::fs::create_dir_all;
10-
use std::path::Path;
10+
use std::path::{Path, PathBuf};
1111
use std::time::Duration;
1212

1313
#[cfg(unix)]
@@ -16,23 +16,23 @@ use std::os::unix::fs::PermissionsExt;
1616
quick_error! {
1717
#[derive(Debug)]
1818
pub enum Error {
19-
Utf8Error(err: git_object::bstr::Utf8Error) {
19+
Utf8(err: git_object::bstr::Utf8Error) {
2020
from()
2121
display("Could not convert path to UTF8: {}", err)
2222
}
23-
TimeError(err: std::time::SystemTimeError) {
23+
Time(err: std::time::SystemTimeError) {
2424
from()
2525
display("Could not read file time in proper format: {}", err)
2626
}
27-
ToU32Error(err: std::num::TryFromIntError) {
27+
U32Conversion(err: std::num::TryFromIntError) {
2828
from()
2929
display("Could not convert seconds to u32: {}", err)
3030
}
31-
IoError(err: std::io::Error) {
31+
Io(err: std::io::Error) {
3232
from()
3333
display("IO error while writing blob or reading file metadata or changing filetype: {}", err)
3434
}
35-
FindOidError(oid: git_hash::ObjectId, path: std::path::PathBuf) {
35+
NotFound(oid: git_hash::ObjectId, path: PathBuf) {
3636
display("unable to read sha1 file of {} ({})", path.display(), oid.to_hex())
3737
}
3838
}
@@ -56,7 +56,7 @@ where
5656
create_dir_all(dest.parent().expect("entry paths are never empty"))?;
5757
match entry.mode {
5858
git_index::entry::Mode::FILE | git_index::entry::Mode::FILE_EXECUTABLE => {
59-
let obj = find(&entry.id, &mut buf).ok_or_else(|| Error::FindOidError(entry.id, path.to_path_buf()))?;
59+
let obj = find(&entry.id, &mut buf).ok_or_else(|| Error::NotFound(entry.id, path.to_path_buf()))?;
6060
std::fs::write(&dest, obj.data)?;
6161
if entry.mode == git_index::entry::Mode::FILE_EXECUTABLE {
6262
#[cfg(unix)]
@@ -72,7 +72,7 @@ where
7272
entry_time.push((ctime?, mtime?, i));
7373
}
7474
git_index::entry::Mode::SYMLINK => {
75-
let obj = find(&entry.id, &mut buf).unwrap();
75+
let obj = find(&entry.id, &mut buf).ok_or_else(|| Error::NotFound(entry.id, path.to_path_buf()))?;
7676
let linked_to = obj.data.to_path()?;
7777
if opts.symlinks {
7878
#[cfg(unix)]

0 commit comments

Comments
 (0)