Skip to content

Commit

Permalink
Replace eyre with miette
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Dec 6, 2023
1 parent da99799 commit 940df67
Show file tree
Hide file tree
Showing 48 changed files with 331 additions and 260 deletions.
218 changes: 138 additions & 80 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions crates/kitsune-activitypub/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use diesel_async::pooled_connection::deadpool::PoolError as DatabasePoolError;
use kitsune_core::error::BoxError;
use kitsune_http_signatures::ring;
use rsa::pkcs8::der;
use std::convert::Infallible;
use std::{
convert::Infallible,
fmt::{Debug, Display},
};
use thiserror::Error;

pub type Result<T, E = Error> = std::result::Result<T, E>;
Expand Down Expand Up @@ -90,7 +93,7 @@ impl From<Infallible> for Error {

impl<E> From<kitsune_db::PoolError<E>> for Error
where
E: Into<Error>,
E: Into<Error> + Debug + Display,
{
fn from(value: kitsune_db::PoolError<E>) -> Self {
match value {
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition.workspace = true
version.workspace = true

[dependencies]
eyre = "0.6.9"
miette = "5.10.0"
serde = { version = "1.0.193", features = ["derive"] }
smol_str = { version = "0.2.0", features = ["serde"] }
tokio = { version = "1.34.0", features = ["fs"] }
Expand Down
13 changes: 10 additions & 3 deletions crates/kitsune-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod server;
pub mod storage;
pub mod url;

use miette::{Context, IntoDiagnostic};
use serde::{Deserialize, Serialize};
use std::path::Path;
use tokio::fs;
Expand All @@ -36,11 +37,17 @@ pub struct Configuration {
}

impl Configuration {
pub async fn load<P>(path: P) -> eyre::Result<Self>
pub async fn load<P>(path: P) -> miette::Result<Self>
where
P: AsRef<Path>,
{
let content = fs::read_to_string(path).await?;
toml::from_str(&content).map_err(eyre::Report::from)
let content = fs::read_to_string(path)
.await
.into_diagnostic()
.wrap_err("Couldn't read configuration file")?;

toml::from_str(&content)
.into_diagnostic()
.wrap_err("Failed to parse configuration file")
}
}
1 change: 1 addition & 0 deletions crates/kitsune-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ iso8601-timestamp = { version = "0.2.12", features = ["diesel-pg"] }
kitsune-blocking = { path = "../kitsune-blocking" }
kitsune-language = { path = "../kitsune-language" }
kitsune-type = { path = "../kitsune-type" }
miette = "5.10.0"
num-derive = "0.4.1"
num-traits = "0.2.17"
serde = { version = "1.0.193", features = ["derive"] }
Expand Down
4 changes: 3 additions & 1 deletion crates/kitsune-db/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use core::fmt;
use diesel_async::pooled_connection::deadpool::PoolError;
use miette::Diagnostic;
use std::error::Error as StdError;
use thiserror::Error;

pub type BoxError = Box<dyn StdError + Send + Sync>;
pub type Result<T, E = Error> = std::result::Result<T, E>;
Expand Down Expand Up @@ -35,7 +37,7 @@ impl fmt::Display for IsoCodeConversionError {

impl StdError for IsoCodeConversionError {}

#[derive(Debug, thiserror::Error)]
#[derive(Debug, Diagnostic, Error)]
pub enum Error {
#[error(transparent)]
Blocking(#[from] kitsune_blocking::Error),
Expand Down
16 changes: 12 additions & 4 deletions crates/kitsune-db/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ use diesel_async::{
scoped_futures::{ScopedBoxFuture, ScopedFutureWrapper},
AsyncConnection, AsyncPgConnection,
};
use std::future::Future;
use miette::Diagnostic;
use std::{
fmt::{Debug, Display},
future::Future,
};
use thiserror::Error;

#[derive(Debug, Error)]
pub enum PoolError<E> {
#[derive(Debug, Diagnostic, Error)]
pub enum PoolError<E>
where
E: Display + Debug,
{
#[error(transparent)]
Pool(#[from] DeadpoolError),

Expand Down Expand Up @@ -35,6 +42,7 @@ impl PgPool {
for<'conn> F:
FnOnce(&'conn mut Object<AsyncPgConnection>) -> ScopedFutureWrapper<'conn, 'a, Fut>,
Fut: Future<Output = Result<T, E>>,
E: Display + Debug,
{
let mut conn = self.inner.get().await?;
func(&mut conn).await.map_err(PoolError::User)
Expand All @@ -48,7 +56,7 @@ impl PgPool {
) -> ScopedBoxFuture<'a, 'r, Result<R, E>>
+ Send
+ 'a,
E: From<diesel::result::Error> + Send + 'a,
E: From<diesel::result::Error> + Debug + Display + Send + 'a,
R: Send + 'a,
{
let mut conn = self.inner.get().await?;
Expand Down
1 change: 1 addition & 0 deletions crates/kitsune-email/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ lettre = { version = "0.11.2", default-features = false, features = [
"tokio1-rustls-tls",
"tracing",
] }
miette = "5.10.0"
mrml = { version = "2.0.0-rc4", default-features = false, features = [
"orderedmap",
"parse",
Expand Down
10 changes: 7 additions & 3 deletions crates/kitsune-email/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use diesel_async::pooled_connection::deadpool::PoolError as DatabasePoolError;
use std::error::Error as StdError;
use miette::Diagnostic;
use std::{
error::Error as StdError,
fmt::{Debug, Display},
};
use thiserror::Error;

pub type BoxError = Box<dyn StdError + Send + Sync>;
pub type Result<T, E = Error> = std::result::Result<T, E>;

#[derive(Debug, Error)]
#[derive(Debug, Diagnostic, Error)]
pub enum Error {
#[error(transparent)]
Address(#[from] lettre::address::AddressError),
Expand Down Expand Up @@ -34,7 +38,7 @@ pub enum Error {

impl<E> From<kitsune_db::PoolError<E>> for Error
where
E: Into<Error>,
E: Into<Error> + Debug + Display,
{
fn from(value: kitsune_db::PoolError<E>) -> Self {
match value {
Expand Down
3 changes: 2 additions & 1 deletion crates/kitsune-embed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use kitsune_http_client::Client as HttpClient;
use once_cell::sync::Lazy;
use scraper::{Html, Selector};
use smol_str::SmolStr;
use std::fmt::{Debug, Display};
use typed_builder::TypedBuilder;

pub use embed_sdk;
Expand Down Expand Up @@ -47,7 +48,7 @@ pub enum Error {

impl<E> From<kitsune_db::PoolError<E>> for Error
where
E: Into<Error>,
E: Into<Error> + Debug + Display,
{
fn from(value: kitsune_db::PoolError<E>) -> Self {
match value {
Expand Down
1 change: 1 addition & 0 deletions crates/kitsune-federation-filter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version.workspace = true
globset = "0.4.14"
kitsune-config = { path = "../kitsune-config" }
kitsune-type = { path = "../kitsune-type" }
miette = "5.10.0"
thiserror = "1.0.50"
url = "2.5.0"

Expand Down
3 changes: 2 additions & 1 deletion crates/kitsune-federation-filter/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use miette::Diagnostic;
use thiserror::Error;

pub type Result<T, E = Error> = std::result::Result<T, E>;

#[derive(Debug, Error)]
#[derive(Debug, Diagnostic, Error)]
pub enum Error {
#[error(transparent)]
Glob(#[from] globset::Error),
Expand Down
3 changes: 1 addition & 2 deletions crates/kitsune-jobs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ athena = { path = "../../lib/athena" }
derive_more = { version = "1.0.0-beta.6", features = ["from"] }
diesel = "2.1.4"
diesel-async = "0.4.1"
eyre = "0.6.9"
futures-util = "0.3.29"
kitsune-core = { path = "../kitsune-core" }
kitsune-db = { path = "../kitsune-db" }
kitsune-email = { path = "../kitsune-email" }
miette = "5.10.0"
scoped-futures = "0.1.3"
serde = { version = "1.0.193", features = ["derive"] }
speedy-uuid = { path = "../../lib/speedy-uuid" }
thiserror = "1.0.50"
tracing = "0.1.40"
typed-builder = "0.18.0"

Expand Down
9 changes: 3 additions & 6 deletions crates/kitsune-jobs/src/deliver/accept.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
error::{Error, Result},
JobRunnerContext, Runnable,
};
use crate::{JobRunnerContext, Runnable};
use diesel::{OptionalExtension, QueryDsl};
use diesel_async::RunQueryDsl;
use kitsune_core::traits::deliverer::Action;
Expand All @@ -17,7 +14,7 @@ pub struct DeliverAccept {

impl Runnable for DeliverAccept {
type Context = JobRunnerContext;
type Error = eyre::Report;
type Error = miette::Report;

#[instrument(skip_all, fields(follow_id = %self.follow_id))]
async fn run(&self, ctx: &Self::Context) -> Result<(), Self::Error> {
Expand All @@ -42,7 +39,7 @@ impl Runnable for DeliverAccept {
ctx.deliverer
.deliver(Action::AcceptFollow(follow))
.await
.map_err(Error::Delivery)?;
.map_err(|err| miette::Report::new_boxed(err.into()))?;

Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/kitsune-jobs/src/deliver/create.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{error::Error, JobRunnerContext};
use crate::JobRunnerContext;
use athena::Runnable;
use diesel::{OptionalExtension, QueryDsl, SelectableHelper};
use diesel_async::RunQueryDsl;
Expand All @@ -15,7 +15,7 @@ pub struct DeliverCreate {

impl Runnable for DeliverCreate {
type Context = JobRunnerContext;
type Error = eyre::Report;
type Error = miette::Report;

#[instrument(skip_all, fields(post_id = %self.post_id))]
async fn run(&self, ctx: &Self::Context) -> Result<(), Self::Error> {
Expand All @@ -41,7 +41,7 @@ impl Runnable for DeliverCreate {
ctx.deliverer
.deliver(Action::Create(post))
.await
.map_err(Error::Delivery)?;
.map_err(|err| miette::Report::new_boxed(err.into()))?;

Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/kitsune-jobs/src/deliver/delete.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{error::Error, JobRunnerContext};
use crate::JobRunnerContext;
use athena::Runnable;
use diesel::{OptionalExtension, QueryDsl, SelectableHelper};
use diesel_async::RunQueryDsl;
Expand All @@ -15,7 +15,7 @@ pub struct DeliverDelete {

impl Runnable for DeliverDelete {
type Context = JobRunnerContext;
type Error = eyre::Report;
type Error = miette::Report;

#[instrument(skip_all, fields(post_id = %self.post_id))]
async fn run(&self, ctx: &Self::Context) -> Result<(), Self::Error> {
Expand All @@ -41,7 +41,7 @@ impl Runnable for DeliverDelete {
ctx.deliverer
.deliver(Action::Delete(post))
.await
.map_err(Error::Delivery)?;
.map_err(|err| miette::Report::new_boxed(err.into()))?;

ctx.db_pool
.with_connection(|db_conn| {
Expand Down
6 changes: 3 additions & 3 deletions crates/kitsune-jobs/src/deliver/favourite.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{error::Error, JobRunnerContext};
use crate::JobRunnerContext;
use athena::Runnable;
use diesel::QueryDsl;
use diesel_async::RunQueryDsl;
Expand All @@ -15,7 +15,7 @@ pub struct DeliverFavourite {

impl Runnable for DeliverFavourite {
type Context = JobRunnerContext;
type Error = eyre::Report;
type Error = miette::Report;

#[instrument(skip_all, fields(favourite_id = %self.favourite_id))]
async fn run(&self, ctx: &Self::Context) -> Result<(), Self::Error> {
Expand All @@ -32,7 +32,7 @@ impl Runnable for DeliverFavourite {
ctx.deliverer
.deliver(Action::Favourite(favourite))
.await
.map_err(Error::Delivery)?;
.map_err(|err| miette::Report::new_boxed(err.into()))?;

Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/kitsune-jobs/src/deliver/follow.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{error::Error, JobRunnerContext};
use crate::JobRunnerContext;
use athena::Runnable;
use diesel::{OptionalExtension, QueryDsl};
use diesel_async::RunQueryDsl;
Expand All @@ -15,7 +15,7 @@ pub struct DeliverFollow {

impl Runnable for DeliverFollow {
type Context = JobRunnerContext;
type Error = eyre::Report;
type Error = miette::Report;

#[instrument(skip_all, fields(follow_id = %self.follow_id))]
async fn run(&self, ctx: &Self::Context) -> Result<(), Self::Error> {
Expand All @@ -40,7 +40,7 @@ impl Runnable for DeliverFollow {
ctx.deliverer
.deliver(Action::Follow(follow))
.await
.map_err(Error::Delivery)?;
.map_err(|err| miette::Report::new_boxed(err.into()))?;

Ok(())
}
Expand Down
9 changes: 3 additions & 6 deletions crates/kitsune-jobs/src/deliver/reject.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
error::{Error, Result},
JobRunnerContext, Runnable,
};
use crate::{JobRunnerContext, Runnable};
use diesel::{OptionalExtension, QueryDsl};
use diesel_async::RunQueryDsl;
use kitsune_core::traits::deliverer::Action;
Expand All @@ -17,7 +14,7 @@ pub struct DeliverReject {

impl Runnable for DeliverReject {
type Context = JobRunnerContext;
type Error = eyre::Report;
type Error = miette::Report;

#[instrument(skip_all, fields(follow_id = %self.follow_id))]
async fn run(&self, ctx: &Self::Context) -> Result<(), Self::Error> {
Expand All @@ -42,7 +39,7 @@ impl Runnable for DeliverReject {
ctx.deliverer
.deliver(Action::RejectFollow(follow))
.await
.map_err(Error::Delivery)?;
.map_err(|err| miette::Report::new_boxed(err.into()))?;

ctx.db_pool
.with_connection(|db_conn| {
Expand Down
6 changes: 3 additions & 3 deletions crates/kitsune-jobs/src/deliver/unfavourite.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{error::Error, JobRunnerContext};
use crate::JobRunnerContext;
use athena::Runnable;
use diesel::{OptionalExtension, QueryDsl};
use diesel_async::RunQueryDsl;
Expand All @@ -15,7 +15,7 @@ pub struct DeliverUnfavourite {

impl Runnable for DeliverUnfavourite {
type Context = JobRunnerContext;
type Error = eyre::Report;
type Error = miette::Report;

#[instrument(skip_all, fields(favourite_id = %self.favourite_id))]
async fn run(&self, ctx: &Self::Context) -> Result<(), Self::Error> {
Expand All @@ -40,7 +40,7 @@ impl Runnable for DeliverUnfavourite {
ctx.deliverer
.deliver(Action::Unfavourite(favourite))
.await
.map_err(Error::Delivery)?;
.map_err(|err| miette::Report::new_boxed(err.into()))?;

ctx.db_pool
.with_connection(|db_conn| {
Expand Down
Loading

0 comments on commit 940df67

Please sign in to comment.