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 */
use anyhow::{Error, Result};
use anyhow::{anyhow, Result};
use inotify::{Event, EventMask, EventStream, Inotify, WatchDescriptor, WatchMask};
use std::collections::HashMap;
use std::ffi::OsString;
@ -238,7 +238,7 @@ impl Inhibitor {
Some(fname) => PathBuf::from(fname),
None => {
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());

View file

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

View file

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