Skip to content

Commit 93af9cb

Browse files
authored
feat(lambda-extension): make errors implement Debug+Display (#419)
1 parent 854ca9c commit 93af9cb

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

lambda-extension/src/extension.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::{logs::*, requests, Error, ExtensionError, LambdaEvent, NextEvent};
22
use hyper::{server::conn::AddrStream, Server};
33
use lambda_runtime_api_client::Client;
4-
use std::{fmt, future::ready, future::Future, net::SocketAddr, path::PathBuf, pin::Pin, sync::Arc};
4+
use std::{
5+
convert::Infallible, fmt, future::ready, future::Future, net::SocketAddr, path::PathBuf, pin::Pin, sync::Arc,
6+
};
57
use tokio::sync::Mutex;
68
use tokio_stream::StreamExt;
79
use tower::{service_fn, MakeService, Service};
@@ -45,14 +47,14 @@ impl<'a, E, L> Extension<'a, E, L>
4547
where
4648
E: Service<LambdaEvent>,
4749
E::Future: Future<Output = Result<(), E::Error>>,
48-
E::Error: Into<Box<dyn std::error::Error + Send + Sync>> + fmt::Display,
50+
E::Error: Into<Box<dyn std::error::Error + Send + Sync>> + fmt::Display + fmt::Debug,
4951

5052
// Fixme: 'static bound might be too restrictive
5153
L: MakeService<(), Vec<LambdaLog>, Response = ()> + Send + Sync + 'static,
5254
L::Service: Service<Vec<LambdaLog>, Response = ()> + Send + Sync,
5355
<L::Service as Service<Vec<LambdaLog>>>::Future: Send + 'a,
54-
L::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
55-
L::MakeError: Into<Box<dyn std::error::Error + Send + Sync>>,
56+
L::Error: Into<Box<dyn std::error::Error + Send + Sync>> + fmt::Debug,
57+
L::MakeError: Into<Box<dyn std::error::Error + Send + Sync>> + fmt::Debug,
5658
L::Future: Send,
5759
{
5860
/// Create a new [`Extension`] with a given extension name
@@ -199,6 +201,7 @@ where
199201

200202
let res = ep.call(event).await;
201203
if let Err(error) = res {
204+
println!("{:?}", error);
202205
let req = if is_invoke {
203206
requests::init_error(extension_id, &error.to_string(), None)?
204207
} else {
@@ -228,8 +231,8 @@ impl<T> Identity<T> {
228231
}
229232

230233
impl<T> Service<T> for Identity<T> {
231-
type Error = Error;
232-
type Future = Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>;
234+
type Error = Infallible;
235+
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
233236
type Response = ();
234237

235238
fn poll_ready(&mut self, _cx: &mut core::task::Context<'_>) -> core::task::Poll<Result<(), Self::Error>> {
@@ -251,7 +254,7 @@ impl<T> Service<()> for MakeIdentity<T>
251254
where
252255
T: Send + Sync + 'static,
253256
{
254-
type Error = Error;
257+
type Error = Infallible;
255258
type Response = Identity<T>;
256259
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
257260

lambda-extension/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub async fn run<E>(events_processor: E) -> Result<(), Error>
2626
where
2727
E: Service<LambdaEvent>,
2828
E::Future: Future<Output = Result<(), E::Error>>,
29-
E::Error: Into<Box<dyn std::error::Error + Send + Sync>> + fmt::Display,
29+
E::Error: Into<Box<dyn std::error::Error + Send + Sync>> + fmt::Display + fmt::Debug,
3030
{
3131
let ext = Extension::new().with_events_processor(events_processor);
3232
ext.run().await

lambda-extension/src/logs.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use chrono::{DateTime, Utc};
22
use serde::{Deserialize, Serialize};
3-
use std::{boxed::Box, sync::Arc};
3+
use std::{boxed::Box, fmt, sync::Arc};
44
use tokio::sync::Mutex;
55
use tower::Service;
66
use tracing::{error, trace};
@@ -144,7 +144,7 @@ pub(crate) async fn log_wrapper<S>(
144144
) -> Result<hyper::Response<hyper::Body>, Box<dyn std::error::Error + Send + Sync>>
145145
where
146146
S: Service<Vec<LambdaLog>, Response = ()>,
147-
S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
147+
S::Error: Into<Box<dyn std::error::Error + Send + Sync>> + fmt::Debug,
148148
S::Future: Send,
149149
{
150150
trace!("Received logs request");
@@ -172,7 +172,10 @@ where
172172

173173
{
174174
let mut service = service.lock().await;
175-
let _ = service.call(logs).await;
175+
match service.call(logs).await {
176+
Ok(_) => (),
177+
Err(err) => println!("{:?}", err),
178+
}
176179
}
177180

178181
Ok(hyper::Response::new(hyper::Body::empty()))

0 commit comments

Comments
 (0)