chore: moving to color_eyre

This commit is contained in:
Justin Miller
2021-10-10 19:26:34 -06:00
committed by Aiden McClelland
parent 36bae894a9
commit 81164f974f
38 changed files with 380 additions and 180 deletions

View File

@@ -100,7 +100,7 @@ where
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).await?;
serde_yaml::from_slice(&buffer)
.map_err(anyhow::Error::from)
.map_err(color_eyre::eyre::Error::from)
.with_kind(crate::ErrorKind::Deserialization)
}
@@ -123,7 +123,7 @@ where
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).await?;
serde_toml::from_slice(&buffer)
.map_err(anyhow::Error::from)
.map_err(color_eyre::eyre::Error::from)
.with_kind(crate::ErrorKind::Deserialization)
}
@@ -146,7 +146,7 @@ where
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).await?;
serde_cbor::de::from_reader(buffer.as_slice())
.map_err(anyhow::Error::from)
.map_err(color_eyre::eyre::Error::from)
.with_kind(crate::ErrorKind::Deserialization)
}
@@ -158,7 +158,7 @@ where
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).await?;
serde_json::from_slice(&buffer)
.map_err(anyhow::Error::from)
.map_err(color_eyre::eyre::Error::from)
.with_kind(crate::ErrorKind::Deserialization)
}

View File

@@ -7,9 +7,9 @@ use std::process::{exit, Stdio};
use std::str::FromStr;
use std::time::Duration;
use anyhow::anyhow;
use async_trait::async_trait;
use clap::ArgMatches;
use color_eyre::eyre::{self, eyre};
use digest::Digest;
use patch_db::{HasModel, Model};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
@@ -166,14 +166,14 @@ pub async fn daemon<F: FnMut() -> Fut, Fut: Future<Output = ()> + Send + 'static
mut f: F,
cooldown: std::time::Duration,
mut shutdown: tokio::sync::broadcast::Receiver<Option<Shutdown>>,
) -> Result<(), anyhow::Error> {
) -> Result<(), eyre::Error> {
loop {
tokio::select! {
_ = shutdown.recv() => return Ok(()),
_ = tokio::time::sleep(cooldown) => (),
}
match tokio::spawn(f()).await {
Err(e) if e.is_panic() => return Err(anyhow!("daemon panicked!")),
Err(e) if e.is_panic() => return Err(eyre!("daemon panicked!")),
_ => (),
}
}
@@ -647,7 +647,7 @@ pub fn parse_stdin_deserializable<T: for<'de> Deserialize<'de>>(
pub fn parse_duration(arg: &str, _: &ArgMatches<'_>) -> Result<Duration, Error> {
let units_idx = arg.find(|c: char| c.is_alphabetic()).ok_or_else(|| {
Error::new(
anyhow!("Must specify units for duration"),
eyre!("Must specify units for duration"),
crate::ErrorKind::Deserialization,
)
})?;
@@ -665,7 +665,7 @@ pub fn parse_duration(arg: &str, _: &ArgMatches<'_>) -> Result<Duration, Error>
"us" => Ok(Duration::from_micros(num.parse()?)),
"ns" => Ok(Duration::from_nanos(num.parse()?)),
_ => Err(Error::new(
anyhow!("Invalid units for duration"),
eyre!("Invalid units for duration"),
crate::ErrorKind::Deserialization,
)),
}