Skip to content

Commit

Permalink
bridge: Use boxed error instead of io::Error for ReceiverOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte committed Jun 19, 2024
1 parent a5eb225 commit d3002e9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bridge/svix-bridge-plugin-queue/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum Error {
#[error("{0}")]
Generic(String),
}
pub type Result<T> = std::result::Result<T, Error>;
pub type Result<T, E = Error> = std::result::Result<T, E>;

impl From<Error> for std::io::Error {
fn from(value: Error) -> Self {
Expand Down
12 changes: 5 additions & 7 deletions bridge/svix-bridge-plugin-queue/src/receiver_output/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use omniqueue::DynProducer;
use svix_bridge_types::{async_trait, ForwardRequest, ReceiverOutput};
use svix_bridge_types::{async_trait, BoxError, ForwardRequest, ReceiverOutput};

use crate::{config::QueueOutputOpts, error::Result};

Expand Down Expand Up @@ -42,11 +42,9 @@ impl ReceiverOutput for QueueForwarder {
fn name(&self) -> &str {
&self.name
}
async fn handle(&self, request: ForwardRequest) -> std::io::Result<()> {
Ok(self
.sender
.send_serde_json(&request.payload)
.await
.map_err(crate::Error::from)?)

async fn handle(&self, request: ForwardRequest) -> Result<(), BoxError> {
self.sender.send_serde_json(&request.payload).await?;
Ok(())
}
}
4 changes: 3 additions & 1 deletion bridge/svix-bridge-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,16 @@ pub trait SenderInput: Send {
async fn run(&self);
}

pub type BoxError = Box<dyn std::error::Error + Send + Sync>;

/// Represents something we can hand a webhook payload to.
/// Aka a "forwarder."
///
/// To start, we're only using this in conjunction with an HTTP server "owned" by the bridge binary.
#[async_trait]
pub trait ReceiverOutput: Send + Sync {
fn name(&self) -> &str;
async fn handle(&self, request: ForwardRequest) -> std::io::Result<()>;
async fn handle(&self, request: ForwardRequest) -> Result<(), BoxError>;
}

#[derive(Deserialize, Debug, Clone, Default)]
Expand Down
9 changes: 5 additions & 4 deletions bridge/svix-bridge/src/webhook_receiver/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use axum::{
};
use serde_json::json;
use svix_bridge_types::{
async_trait, svix::webhooks::Webhook, ForwardRequest, ReceiverOutput, TransformationConfig,
TransformerInput, TransformerInputFormat, TransformerJob, TransformerOutput,
async_trait, svix::webhooks::Webhook, BoxError, ForwardRequest, ReceiverOutput,
TransformationConfig, TransformerInput, TransformerInputFormat, TransformerJob,
TransformerOutput,
};
use tower::{Service, ServiceExt};

Expand Down Expand Up @@ -37,8 +38,8 @@ impl ReceiverOutput for FakeReceiverOutput {
"fake output"
}

async fn handle(&self, request: ForwardRequest) -> std::io::Result<()> {
self.tx.send(request.payload).unwrap();
async fn handle(&self, request: ForwardRequest) -> Result<(), BoxError> {
self.tx.send(request.payload)?;
Ok(())
}
}
Expand Down

0 comments on commit d3002e9

Please sign in to comment.