fix: make "other" error actually transparent

This commit is contained in:
phiresky 2023-06-23 23:10:29 +02:00
parent 7300940e10
commit bd7391e344
5 changed files with 23 additions and 11 deletions

View file

@ -56,7 +56,6 @@ axum = { version = "0.6.18", features = [
], default-features = false, optional = true }
tower = { version = "0.4.13", optional = true }
hyper = { version = "0.14", optional = true }
displaydoc = "0.2.4"
[features]
default = ["actix-web", "axum"]

View file

@ -10,7 +10,7 @@ use crate::{
traits::{ActivityHandler, Actor},
FEDERATION_CONTENT_TYPE,
};
use anyhow::anyhow;
use anyhow::{anyhow, Context};
use bytes::Bytes;
use futures_core::Future;
@ -166,7 +166,8 @@ async fn sign_and_send(
task.private_key.clone(),
task.http_signature_compat,
)
.await?;
.await
.context("signing request")?;
retry(
|| {

View file

@ -8,6 +8,7 @@ use crate::{
traits::{ActivityHandler, Actor, Object},
};
use actix_web::{web::Bytes, HttpRequest, HttpResponse};
use anyhow::Context;
use serde::de::DeserializeOwned;
use tracing::debug;

View file

@ -1,27 +1,33 @@
//! Error messages returned by this library
use displaydoc::Display;
/// Error messages returned by this library
#[derive(thiserror::Error, Debug, Display)]
#[derive(thiserror::Error, Debug)]
pub enum Error {
/// Object was not found in local database
#[error("Object was not found in local database")]
NotFound,
/// Request limit was reached during fetch
#[error("Request limit was reached during fetch")]
RequestLimit,
/// Response body limit was reached during fetch
#[error("Response body limit was reached during fetch")]
ResponseBodyLimit,
/// Object to be fetched was deleted
#[error("Object to be fetched was deleted")]
ObjectDeleted,
/// {0}
/// url verification error
#[error("{0}")]
UrlVerificationError(&'static str),
/// Incoming activity has invalid digest for body
#[error("Incoming activity has invalid digest for body")]
ActivityBodyDigestInvalid,
/// Incoming activity has invalid signature
#[error("Incoming activity has invalid signature")]
ActivitySignatureInvalid,
/// Failed to resolve actor via webfinger
#[error("Failed to resolve actor via webfinger")]
WebfingerResolveFailed,
/// Other errors which are not explicitly handled
/// other error
#[error(transparent)]
Other(#[from] anyhow::Error),
}

View file

@ -12,6 +12,7 @@ use crate::{
protocol::public_key::main_key_id,
traits::{Actor, Object},
};
use anyhow::Context;
use base64::{engine::general_purpose::STANDARD as Base64, Engine};
use bytes::Bytes;
use http::{header::HeaderName, uri::PathAndQuery, HeaderValue, Method, Uri};
@ -102,10 +103,14 @@ pub(crate) async fn sign_request(
Sha256::new(),
activity,
move |signing_string| {
let mut signer = Signer::new(MessageDigest::sha256(), &private_key)?;
signer.update(signing_string.as_bytes())?;
let mut signer = Signer::new(MessageDigest::sha256(), &private_key)
.context("instantiating signer")?;
signer
.update(signing_string.as_bytes())
.context("updating signer")?;
Ok(Base64.encode(signer.sign_to_vec()?)) as Result<_, anyhow::Error>
Ok(Base64.encode(signer.sign_to_vec().context("sign to vec")?))
as Result<_, anyhow::Error>
},
)
.await