Skip to content

Commit

Permalink
start error repr rework
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Apr 3, 2024
1 parent 0a92aeb commit 7b53854
Show file tree
Hide file tree
Showing 16 changed files with 484 additions and 270 deletions.
296 changes: 157 additions & 139 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ members = [
"lib/tower-http-digest",
"lib/tower-stop-using-brave",
"lib/tower-x-clacks-overhead",
"lib/trials",
"lib/trials/macros",
"xtask",
]
resolver = "2"
Expand Down Expand Up @@ -117,4 +119,3 @@ install-updater = true

[patch.crates-io]
diesel-async = { git = "https://github.com/weiznich/diesel_async.git", rev = "017ebe2fb7a2709ab5db92148dea5ce812a35e09" }
tokio-postgres-rustls = { git = "https://github.com/jbg/tokio-postgres-rustls.git", rev = "b3b59ac2fa1b5823f2426fef78a0fb74c004ec38" }
2 changes: 1 addition & 1 deletion crates/kitsune-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ speedy-uuid = { path = "../../lib/speedy-uuid", features = ["diesel"] }
thiserror = "1.0.58"
tokio = { version = "1.37.0", features = ["rt"] }
tokio-postgres = "0.7.10"
tokio-postgres-rustls = "0.11.1"
tokio-postgres-rustls = "0.12.0"
tracing = "0.1.40"
tracing-log = "0.2.0"
typed-builder = "0.18.1"
Expand Down
104 changes: 38 additions & 66 deletions crates/kitsune-service/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,60 +37,12 @@ pub enum UserError {

#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
Attachment(#[from] AttachmentError),

#[error(transparent)]
Blocking(#[from] blowocking::Error),

#[error(transparent)]
Cache(#[from] kitsune_cache::Error),

#[error(transparent)]
Captcha(#[from] kitsune_captcha::Error),

#[error(transparent)]
DatabasePool(#[from] bb8::RunError),

#[error(transparent)]
Der(#[from] pkcs8::der::Error),

#[error(transparent)]
Diesel(#[from] diesel::result::Error),

#[error(transparent)]
Email(#[from] kitsune_email::error::Error),

#[error(transparent)]
Embed(#[from] kitsune_embed::Error),

#[error(transparent)]
Event(kitsune_messaging::BoxError),

#[error(transparent)]
Fetcher(eyre::Report),

#[error(transparent)]
Http(#[from] http::Error),

#[error(transparent)]
HttpClient(#[from] kitsune_http_client::Error),

#[error(transparent)]
HttpHeaderToStr(#[from] http::header::ToStrError),

#[error(transparent)]
JobQueue(#[from] athena::Error),

#[error(transparent)]
Mime(#[from] mime::FromStrError),

#[error(transparent)]
PasswordHash(#[from] password_hash::Error),

#[error(transparent)]
Pkcs8(#[from] pkcs8::Error),

#[error(transparent)]
Post(#[from] PostError),

Expand All @@ -100,30 +52,50 @@ pub enum Error {
#[error(transparent)]
Resolver(eyre::Report),

#[error(transparent)]
Rsa(#[from] rsa::Error),

#[error(transparent)]
Search(#[from] kitsune_search::Error),

#[error(transparent)]
SimdJson(#[from] simd_json::Error),

#[error(transparent)]
Spki(#[from] pkcs8::spki::Error),

#[error(transparent)]
Storage(kitsune_storage::BoxError),

#[error(transparent)]
UriInvalid(#[from] http::uri::InvalidUri),
Validate(#[from] garde::Report),

#[error(transparent)]
UrlParse(#[from] url::ParseError),
Other(eyre::Report),
}

#[error(transparent)]
User(#[from] UserError),
macro_rules! other_error {
($($err_ty:path),+$(,)?) => {
$(
impl From<$err_ty> for Error {
fn from(err: $err_ty) -> Self {
Self::Other(err.into())
}

Check warning on line 71 in crates/kitsune-service/src/error.rs

View check run for this annotation

Codecov / codecov/patch

crates/kitsune-service/src/error.rs#L69-L71

Added lines #L69 - L71 were not covered by tests
}
)+
};
}

#[error(transparent)]
Validate(#[from] garde::Report),
other_error! {
athena::Error,
AttachmentError,
bb8::RunError,
blowocking::Error,
diesel::result::Error,
http::Error,
http::header::ToStrError,
http::uri::InvalidUri,
kitsune_cache::Error,
kitsune_captcha::Error,
kitsune_email::error::Error,
kitsune_embed::Error,
kitsune_http_client::Error,
kitsune_search::Error,
mime::FromStrError,
password_hash::Error,
pkcs8::Error,
pkcs8::der::Error,
pkcs8::spki::Error,
rsa::Error,
simd_json::Error,
url::ParseError,
UserError,
}
2 changes: 1 addition & 1 deletion crates/kitsune-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bubble-bath = "0.1.2"
iso8601-timestamp = "0.2.17"
kitsune-type = { path = "../kitsune-type" }
once_cell = "1.19.0"
pulldown-cmark = { version = "0.10.0", default-features = false, features = [
pulldown-cmark = { version = "0.10.2", default-features = false, features = [
"html",
"simd",
] }
Expand Down
4 changes: 2 additions & 2 deletions crates/kitsune-wasm-mrf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tokio = { version = "1.37.0", features = ["fs"] }
tracing = "0.1.40"
typed-builder = "0.18.1"
walkdir = "2.5.0"
wasmtime = { version = "19.0.0", default-features = false, features = [
wasmtime = { version = "19.0.1", default-features = false, features = [
"addr2line",
"async",
"component-model",
Expand All @@ -40,7 +40,7 @@ wasmtime = { version = "19.0.0", default-features = false, features = [
"pooling-allocator",
"runtime",
] }
wasmtime-wasi = { version = "19.0.0", default-features = false }
wasmtime-wasi = { version = "19.0.1", default-features = false }

[dev-dependencies]
tempfile = "3.10.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-wasm-mrf/example-mrf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["cdylib"]

[dependencies]
rand = "0.8.5"
wit-bindgen = "0.23.0"
wit-bindgen = "0.24.0"

[lints]
workspace = true
2 changes: 1 addition & 1 deletion kitsune/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bytes = "1.6.0"
chrono = { version = "0.4.37", default-features = false }
clap = { version = "4.5.4", features = ["derive", "wrap_help"] }
cursiv = { path = "../lib/cursiv", features = ["axum"] }
der = { version = "0.7.8", features = ["std"] }
der = { version = "0.7.9", features = ["std"] }
diesel = "2.1.5"
diesel-async = "0.4.1"
futures-util = "0.3.30"
Expand Down
85 changes: 35 additions & 50 deletions kitsune/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,84 +17,72 @@ pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
ActivityPub(#[from] kitsune_activitypub::error::Error),

#[error(transparent)]
Blocking(#[from] blowocking::Error),

#[error(transparent)]
Cache(#[from] kitsune_cache::Error),

#[error(transparent)]
CoreHttp(#[from] kitsune_core::error::HttpError),

#[error(transparent)]
Database(#[from] diesel::result::Error),

#[error(transparent)]
DatabasePool(#[from] bb8::RunError),

#[error(transparent)]
Der(#[from] der::Error),

#[error(transparent)]
Fetcher(eyre::Report),

#[error(transparent)]
Http(#[from] http::Error),

#[error(transparent)]
Mailing(#[from] kitsune_email::error::Error),

#[cfg(feature = "mastodon-api")]
#[error(transparent)]
Mastodon(#[from] kitsune_mastodon::error::Error),

#[error(transparent)]
Messaging(kitsune_messaging::BoxError),

#[error(transparent)]
Mrf(#[from] kitsune_wasm_mrf::Error),

#[error(transparent)]
Multipart(#[from] MultipartError),

#[error(transparent)]
OAuth2(#[from] OAuth2Error),

#[cfg(feature = "oidc")]
#[error(transparent)]
Oidc(#[from] kitsune_oidc::Error),

#[error(transparent)]
ParseBool(#[from] ParseBoolError),

#[error(transparent)]
PasswordHash(#[from] password_hash::Error),

#[error("Password mismatch")]
PasswordMismatch,

#[error(transparent)]
Service(#[from] ServiceError),

#[error(transparent)]
SimdJson(#[from] simd_json::Error),

#[error(transparent)]
TokioJoin(#[from] tokio::task::JoinError),

#[error("Unconfirmed email address. Check your inbox!")]
UnconfirmedEmailAddress,

#[error(transparent)]
UrlParse(#[from] url::ParseError),
Other(eyre::Report),
}

#[error(transparent)]
Uuid(#[from] speedy_uuid::Error),
macro_rules! other_error {
($($err_ty:path),+$(,)?) => {
$(
impl From<$err_ty> for Error {
fn from(err: $err_ty) -> Self {
Self::Other(err.into())
}

Check warning on line 57 in kitsune/src/error.rs

View check run for this annotation

Codecov / codecov/patch

kitsune/src/error.rs#L55-L57

Added lines #L55 - L57 were not covered by tests
}
)+
};
}

other_error! {
bb8::RunError,
blowocking::Error,
der::Error,
http::Error,
kitsune_activitypub::error::Error,
kitsune_cache::Error,
kitsune_email::error::Error,
kitsune_wasm_mrf::Error,
MultipartError,
password_hash::Error,
simd_json::Error,
speedy_uuid::Error,
tokio::task::JoinError,
url::ParseError,
}

#[cfg(feature = "mastodon-api")]
other_error!(kitsune_mastodon::error::Error);

#[cfg(feature = "oidc")]
other_error!(kitsune_oidc::Error);

#[derive(Debug, Error)]
pub enum OAuth2Error {
#[error("Missing grant type")]
Expand Down Expand Up @@ -137,9 +125,6 @@ impl IntoResponse for Error {
err @ Self::Service(ServiceError::Post(PostError::Unauthorised)) => {
(StatusCode::UNAUTHORIZED, err.to_string()).into_response()
}
err @ Self::Service(_) => {
(StatusCode::UNSUPPORTED_MEDIA_TYPE, err.to_string()).into_response()
}
error => {
error!(?error, "Error occurred in handler");
StatusCode::INTERNAL_SERVER_ERROR.into_response()
Expand Down
1 change: 1 addition & 0 deletions kitsune/src/http/handler/mastodon/api/v1/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use serde::Deserialize;
use speedy_uuid::Uuid;
use utoipa::ToSchema;

#[allow(dead_code)]
#[derive(ToSchema)]
pub struct CreateAttachment {
pub description: Option<String>,
Expand Down
10 changes: 2 additions & 8 deletions lib/athena/src/queue/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use redis::{streams::StreamId, FromRedisValue, RedisResult};

#[derive(Clone, Debug)]
pub struct StreamAutoClaimReply {
pub start_stream_id: String,
pub claimed_ids: Vec<StreamId>,
pub deleted_ids: Vec<String>,
}

impl FromRedisValue for StreamAutoClaimReply {
Expand All @@ -16,18 +14,14 @@ impl FromRedisValue for StreamAutoClaimReply {
Vec<String>,
);

let (start_stream_id, claimed_ids, deleted_ids): AutoClaimReturnValue =
let (_start_stream_id, claimed_ids, _deleted_ids): AutoClaimReturnValue =

Check warning on line 17 in lib/athena/src/queue/util.rs

View check run for this annotation

Codecov / codecov/patch

lib/athena/src/queue/util.rs#L17

Added line #L17 was not covered by tests
redis::from_redis_value(v)?;

let claimed_ids: Vec<StreamId> = claimed_ids
.into_iter()
.flat_map(|row| row.into_iter().map(|(id, map)| StreamId { id, map }))
.collect();

Ok(Self {
start_stream_id,
claimed_ids,
deleted_ids,
})
Ok(Self { claimed_ids })

Check warning on line 25 in lib/athena/src/queue/util.rs

View check run for this annotation

Codecov / codecov/patch

lib/athena/src/queue/util.rs#L25

Added line #L25 was not covered by tests
}
}
18 changes: 18 additions & 0 deletions lib/trials/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "trials"
authors.workspace = true
edition.workspace = true
version.workspace = true
license = "MIT OR Apache-2.0"

[dependencies]
trials-macros = { path = "macros", optional = true }

[features]
proc-macro = ["dep:trials-macros"]

[dev-dependencies]
futures-test = "0.3.30"

[lints]
workspace = true
Loading

0 comments on commit 7b53854

Please sign in to comment.