Clean up anyhow usage

This commit is contained in:
Vicki Pfau 2024-04-04 17:56:48 -07:00
parent 5f2cebc58b
commit a5dfde2b17
3 changed files with 12 additions and 9 deletions

View file

@ -1,5 +1,5 @@
/* SPDX-License-Identifier: BSD-2-Clause */ /* SPDX-License-Identifier: BSD-2-Clause */
use anyhow::{Error, Result}; use anyhow::{anyhow, Result};
use inotify::{Event, EventMask, EventStream, Inotify, WatchDescriptor, WatchMask}; use inotify::{Event, EventMask, EventStream, Inotify, WatchDescriptor, WatchMask};
use std::collections::HashMap; use std::collections::HashMap;
use std::ffi::OsString; use std::ffi::OsString;
@ -238,7 +238,7 @@ impl Inhibitor {
Some(fname) => PathBuf::from(fname), Some(fname) => PathBuf::from(fname),
None => { None => {
error!("Got an event without an associated filename!"); error!("Got an event without an associated filename!");
return Err(Error::msg("Got an event without an associated filename")); return Err(anyhow!("Got an event without an associated filename"));
} }
}; };
debug!("New device {} found", path.display()); debug!("New device {} found", path.display());

View file

@ -5,7 +5,7 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
use anyhow::{bail, Error, Result}; use anyhow::{anyhow, bail, Error, Result};
use std::path::PathBuf; use std::path::PathBuf;
use tokio::signal::unix::{signal, SignalKind}; use tokio::signal::unix::{signal, SignalKind};
use tokio::task::JoinSet; use tokio::task::JoinSet;
@ -103,7 +103,7 @@ pub fn get_appid(pid: u32) -> Result<Option<u64>> {
}; };
let ppid = match stat.split(' ').nth(1) { let ppid = match stat.split(' ').nth(1) {
Some(ppid) => ppid, Some(ppid) => ppid,
None => return Err(anyhow::Error::msg("stat data invalid")), None => return Err(anyhow!("stat data invalid")),
}; };
let ppid: u32 = ppid.parse()?; let ppid: u32 = ppid.parse()?;
if ppid > 1 { if ppid > 1 {
@ -116,7 +116,10 @@ pub fn get_appid(pid: u32) -> Result<Option<u64>> {
async fn reload() -> Result<()> { async fn reload() -> Result<()> {
loop { loop {
let mut sighup = signal(SignalKind::hangup())?; let mut sighup = signal(SignalKind::hangup())?;
sighup.recv().await.ok_or(Error::msg(""))?; sighup
.recv()
.await
.ok_or(anyhow!("SIGHUP handler failed!"))?;
} }
} }
@ -173,8 +176,8 @@ async fn main() -> Result<()> {
Err(e) => Err(e.into()) Err(e) => Err(e.into())
}, },
_ = tokio::signal::ctrl_c() => Ok(()), _ = tokio::signal::ctrl_c() => Ok(()),
e = sigterm.recv() => e.ok_or(Error::msg("SIGTERM machine broke")), e = sigterm.recv() => e.ok_or(anyhow!("SIGTERM machine broke")),
_ = sigquit.recv() => Err(Error::msg("Got SIGQUIT")), _ = sigquit.recv() => Err(anyhow!("Got SIGQUIT")),
e = reload() => e, e = reload() => e,
} }
.inspect_err(|e| error!("Encountered error running: {e}")); .inspect_err(|e| error!("Encountered error running: {e}"));

View file

@ -1,5 +1,5 @@
/* SPDX-License-Identifier: BSD-2-Clause */ /* SPDX-License-Identifier: BSD-2-Clause */
use anyhow::{Error, Result}; use anyhow::{anyhow, Result};
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt::Debug; use std::fmt::Debug;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -95,7 +95,7 @@ impl Service for Ftrace {
let mut string = String::new(); let mut string = String::new();
self.pipe self.pipe
.as_mut() .as_mut()
.ok_or(Error::msg("BUG: trace_pipe missing"))? .ok_or(anyhow!("BUG: trace_pipe missing"))?
.read_line(&mut string) .read_line(&mut string)
.await?; .await?;
if let Err(e) = self.handle_event(string.trim_end()).await { if let Err(e) = self.handle_event(string.trim_end()).await {