Skip to content

Commit

Permalink
refactor: eyre -> anyhow
Browse files Browse the repository at this point in the history
  • Loading branch information
Stonks3141 committed Nov 3, 2023
1 parent 1b99dd2 commit 87d02e7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 112 deletions.
104 changes: 7 additions & 97 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ serde_with = { version = "3.3", features = ["base64"] }
serde_json = "1.0"
serde_qs = "0.12"
percent-encoding = "2.3"
color-eyre = "0.6"
anyhow = "1.0"
tower-cookies = "0.9"
ring = "0.16"
jsonwebtoken = "8.3"
Expand Down
2 changes: 1 addition & 1 deletion crates/pet-monitor-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ serde_with.workspace = true
serde_json.workspace = true
serde_qs.workspace = true
percent-encoding.workspace = true
color-eyre.workspace = true
anyhow.workspace = true
tower-cookies.workspace = true
ring.workspace = true
jsonwebtoken.workspace = true
Expand Down
4 changes: 1 addition & 3 deletions crates/pet-monitor-app/src/bin/pet-monitor-app/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![warn(clippy::unimplemented)]
#![warn(clippy::dbg_macro)]

use color_eyre::eyre;
use pet_monitor_app::config;
use ring::rand::{SecureRandom, SystemRandom};
use std::{
Expand Down Expand Up @@ -41,7 +40,7 @@ const ARGON2_CONFIG: argon2::Config = argon2::Config {
};

#[tokio::main(flavor = "current_thread")]
async fn main() -> eyre::Result<()> {
async fn main() -> anyhow::Result<()> {
xflags::xflags! {
/// A simple and secure pet monitor for Linux
cmd pet-monitor-app {
Expand Down Expand Up @@ -71,7 +70,6 @@ async fn main() -> eyre::Result<()> {
return Ok(());
}

color_eyre::install()?;
env_logger::init();

let rng = SystemRandom::new();
Expand Down
16 changes: 8 additions & 8 deletions crates/pet-monitor-app/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use color_eyre::eyre::{self, WrapErr};
use anyhow::Context as _;
use mp4_stream::config::Config;
use serde::{Deserialize, Serialize};
use std::{
Expand Down Expand Up @@ -34,7 +34,7 @@ impl ContextManager {
(*self.ctx.read().unwrap()).clone()
}

pub async fn set(&self, ctx: Context) -> eyre::Result<()> {
pub async fn set(&self, ctx: Context) -> anyhow::Result<()> {
*self.ctx.write().unwrap() = ctx.clone();

// Don't mess with the global config file if we don't have a specific path
Expand Down Expand Up @@ -78,34 +78,34 @@ impl Default for Context {
}
}

pub async fn store(path: Option<PathBuf>, ctx: Context) -> eyre::Result<()> {
pub async fn store(path: Option<PathBuf>, ctx: Context) -> anyhow::Result<()> {
spawn_blocking(move || match path {
Some(path) => confy::store_path(&path, ctx.clone()).or_else(|e| {
log::warn!("Writing config failed: {e}, retrying in 10 ms");
sleep(Duration::from_millis(10));
confy::store_path(path, ctx).wrap_err("Failed to store configuration file")
confy::store_path(path, ctx).context("Failed to store configuration file")
}),
None => confy::store("pet-monitor-app", Some("config"), ctx.clone()).or_else(|e| {
log::warn!("Writing config failed: {e}, retrying in 10 ms");
sleep(Duration::from_millis(10));
confy::store("pet-monitor-app", Some("config"), ctx)
.wrap_err("Failed to write config file")
.context("Failed to write config file")
}),
})
.await?
}

pub async fn load(path: Option<PathBuf>) -> eyre::Result<Context> {
pub async fn load(path: Option<PathBuf>) -> anyhow::Result<Context> {
spawn_blocking(move || match path {
Some(path) => confy::load_path(&path).or_else(|e| {
log::warn!("Writing config failed: {e}, retrying in 10 ms");
sleep(Duration::from_millis(10));
confy::load_path(path).wrap_err("Failed to store configuration file")
confy::load_path(path).context("Failed to store configuration file")
}),
None => confy::load("pet-monitor-app", Some("config")).or_else(|e| {
log::warn!("Writing config failed: {e}, retrying in 10 ms");
sleep(Duration::from_millis(10));
confy::load("pet-monitor-app", Some("config")).wrap_err("Failed to write config file")
confy::load("pet-monitor-app", Some("config")).context("Failed to write config file")
}),
})
.await?
Expand Down
3 changes: 1 addition & 2 deletions crates/pet-monitor-app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ struct AppState {
caps: Capabilities,
stream_sub_tx: Option<flume::Sender<StreamSubscriber>>,
}
use color_eyre::eyre;

pub async fn start(conf_path: Option<PathBuf>, ctx: Context, stream: bool) -> eyre::Result<()> {
pub async fn start(conf_path: Option<PathBuf>, ctx: Context, stream: bool) -> anyhow::Result<()> {
let (ctx_manager, cfg_rx) = ContextManager::new(ctx.clone(), conf_path.clone());

let caps = get_capabilities_all()?;
Expand Down

0 comments on commit 87d02e7

Please sign in to comment.