Simplify error handling with anyhow
This commit is contained in:
parent
82569743a3
commit
7f8e14384e
6 changed files with 90 additions and 138 deletions
|
|
@ -1,21 +1,13 @@
|
|||
use crate::message::PortDesc;
|
||||
use crate::Error;
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub fn get_entries() -> Result<Vec<PortDesc>, Error> {
|
||||
Err(Error::NotSupported)
|
||||
pub fn get_entries() -> Result<Vec<PortDesc>> {
|
||||
bail!("Not supported on this operating system");
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn get_entries() -> Result<Vec<PortDesc>, Error> {
|
||||
match get_entries_linux() {
|
||||
Ok(v) => Ok(v),
|
||||
Err(e) => Err(Error::ProcFs(format!("{:?}", e))),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn get_entries_linux() -> procfs::ProcResult<Vec<PortDesc>> {
|
||||
pub fn get_entries() -> Result<Vec<PortDesc>> {
|
||||
use procfs::process::FDTarget;
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue