From a5dfde2b17a64bed70ece1ea1f3d518547a02152 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 4 Apr 2024 17:56:48 -0700 Subject: [PATCH] Clean up anyhow usage --- src/ds_inhibit.rs | 4 ++-- src/main.rs | 13 ++++++++----- src/sls/ftrace.rs | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ds_inhibit.rs b/src/ds_inhibit.rs index 2d8bb9e..b7fb5cb 100644 --- a/src/ds_inhibit.rs +++ b/src/ds_inhibit.rs @@ -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()); diff --git a/src/main.rs b/src/main.rs index 949dd42..12242eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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> { }; 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> { 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}")); diff --git a/src/sls/ftrace.rs b/src/sls/ftrace.rs index 46bbc7c..b98bcf8 100644 --- a/src/sls/ftrace.rs +++ b/src/sls/ftrace.rs @@ -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 {