diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2021-05-13 20:41:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-13 23:41:43 -0400 |
commit | ee6228c2b61c0d20e32df610765838634e1a6361 (patch) | |
tree | 1a47a59c3d628bd4dbc203aa31a2ffbe18f3ce5f /src/utils | |
parent | 1e7668fcaa990d57529bebb321f71aba0263a483 (diff) |
refactor: switch to procfs library (#479)
Switch the Linux proc parts to the procfs library: https://crates.io/crates/procfs.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/error.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/utils/error.rs b/src/utils/error.rs index c9273438..8f8da789 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -2,6 +2,9 @@ use beef::Cow; use std::result; use thiserror::Error; +#[cfg(target_os = "linux")] +use procfs::ProcError; + /// A type alias for handling errors related to Bottom. pub type Result<T> = result::Result<T, BottomError>; @@ -35,6 +38,10 @@ pub enum BottomError { /// An error that just signifies something minor went wrong; no message. #[error("Minor error.")] MinorError, + /// An error to represent errors with procfs + #[cfg(target_os = "linux")] + #[error("Procfs error, {0}")] + ProcfsError(String), } impl From<std::io::Error> for BottomError { @@ -107,3 +114,23 @@ impl From<regex::Error> for BottomError { ) } } + +#[cfg(target_os = "linux")] +impl From<ProcError> for BottomError { + fn from(err: ProcError) -> Self { + match err { + ProcError::PermissionDenied(p) => { + BottomError::ProcfsError(format!("Permission denied for {:?}", p)) + } + ProcError::NotFound(p) => BottomError::ProcfsError(format!("{:?} not found", p)), + ProcError::Incomplete(p) => BottomError::ProcfsError(format!("{:?} incomplete", p)), + ProcError::Io(e, p) => { + BottomError::ProcfsError(format!("io error: {:?} for {:?}", e, p)) + } + ProcError::Other(s) => BottomError::ProcfsError(format!("Other procfs error: {}", s)), + ProcError::InternalError(e) => { + BottomError::ProcfsError(format!("procfs internal error: {:?}", e)) + } + } + } +} |