Skip to content

Commit

Permalink
Removed the two previously added errors.
Browse files Browse the repository at this point in the history
Replaced `ZeroMountPointsFound` and `CantOpenMountPointsFile` with
`panic!` after coming across https://lukaskalbertodt.github.io/2019/11/14/thoughts-on-error-handling-in-rust.html
and reading http://joeduffyblog.com/2016/02/07/the-error-model/
  • Loading branch information
ArturKovacs committed Nov 17, 2019
1 parent 00fc235 commit fa03282
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ pub enum ErrorKind {
/// obtained with `HRESULT_FROM_WIN32(GetLastError())`
PlatformApi { function_name: &'static str, code: Option<i32> },

/// This is a Linux specific Error that occures when neither '/proc/mounts' nor '/etc/mtab'
/// could be opened. This may happen during `remove`, `remove_all`, or `list`
CantOpenMountPointsFile,

/// This is a Linux specific Error that occurs when a mount points file could be opened
/// but the very first call to `getmntent` returned NULL.
ZeroMountPointsFound,

/// Error while canonicalizing path.
///
/// The `source()` function of the `Error` will return a reference to an `std::io::Error`.
Expand Down
9 changes: 4 additions & 5 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ fn home_trash() -> Result<PathBuf, Error> {
return Ok(home_path.join(".local/share/Trash").into());
}
}

panic!("Neither the XDG_DATA_HOME nor the HOME environment variable was found");
}

Expand All @@ -604,7 +603,7 @@ fn get_mount_points() -> Result<Vec<MountPoint>, Error> {
file = unsafe { libc::fopen(mtab_path.as_c_str().as_ptr(), read_arg.as_c_str().as_ptr()) };
}
if file == std::ptr::null_mut() {
return Err(Error::kind_only(ErrorKind::CantOpenMountPointsFile));
panic!("Neither '/proc/mounts' nor '/etc/mtab' could be opened.");
}
defer! {{ unsafe { libc::fclose(file); } }}
let mut result = Vec::new();
Expand All @@ -627,9 +626,9 @@ fn get_mount_points() -> Result<Vec<MountPoint>, Error> {
result.push(mount_point);
}
if result.len() == 0 {
// If the mountpoints file could be opened but no mountpoints are found
// there possibly is a serious issue
return Err(Error::kind_only(ErrorKind::ZeroMountPointsFound));
panic!(
"A mount points file could be opened but the first call to `getmntent` returned NULL."
);
}
Ok(result)
}

0 comments on commit fa03282

Please sign in to comment.